I am trying to implement multiple select product using select2 . the list come up using getproductsearch this ajax action i did earlier but i failed to save it. I did this feature before for post-meta and product-category but failed for plugin option page. I am not sure what i am doing wrong.
please help.
class FeatureSale {
private $feature_sale_options;
public function __construct() {
add_action( 'admin_menu', array( $this, 'feature_sale_add_plugin_page' ) );
add_action( 'admin_init', array( $this, 'feature_sale_page_init' ) );
}
public function feature_sale_add_plugin_page() {
add_submenu_page(
'exclutips-settings',
'Feature & Sale', // page_title
'Feature & Sale', // menu_title
'manage_options', // capability
'feature-sale', // menu_slug
array( $this, 'feature_sale_create_admin_page' ) // function
);
}
public function feature_sale_create_admin_page() {
$this->feature_sale_options = get_option( 'feature_sale_option_name' ); ?>
<div class="wrap">
<div class="catbox-area-admin" style="width: 500px;background: #fff;padding: 27px 50px;">
<h2>Feature & Sale</h2>
<p></p>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<?php
settings_fields( 'feature_sale_option_group' );
do_settings_sections( 'feature-sale-admin' );
submit_button();
?>
</form>
</div>
</div>
<?php }
public function feature_sale_page_init() {
register_setting(
'feature_sale_option_group', // option_group
'feature_sale_option_name', // option_name
array( $this, 'feature_sale_sanitize' ) // sanitize_callback
);
add_settings_section(
'feature_sale_setting_section', // id
'', // title
array( $this, 'feature_sale_section_info' ), // callback
'feature-sale-admin' // page
);
add_settings_field(
'vpm_sale_product', // id
'VPM Sale Product', // title
array( $this, 'vpm_sale_product_callback' ), // callback
'feature-sale-admin', // page
'feature_sale_setting_section' // section
);
add_settings_field(
'vpm_featured_product', // id
'VPM Featured Product', // title
array( $this, 'vpm_featured_product_callback' ), // callback
'feature-sale-admin', // page
'feature_sale_setting_section' // section
);
}
public function feature_sale_sanitize($input) {
$sanitary_values = array();
if ( isset( $input['vpm_sale_product'] ) ) {
$sanitary_values['vpm_sale_product'] = $input['vpm_sale_product'];
}
if ( isset( $input['vpm_featured_product'] ) ) {
$sanitary_values['vpm_featured_product'] = $input['vpm_featured_product'];
}
return $sanitary_values;
}
public function feature_sale_section_info() {
}
//Output the HTML for the metabox.
public function vpm_sale_product_callback() {
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'vpm_sale_product_nonce' );
$html = '';
// always array because we have added [] to our <select> name attribute
$feature_sale_options = get_option( 'feature_sale_option_name' ); // Array of All Options
$vpm_sale_product = $feature_sale_options['vpm_sale_product'];
$html .= '<p><select id="vpm_sale_product" name="vpm_sale_product[]" multiple="multiple" style="width:99%;max-width:25em;">';
if( $vpm_sale_product ) {
foreach( $vpm_sale_product as $post_id ) {
$title = get_the_title( $post_id );
// if the post title is too long, truncate it and add "..." at the end
$title = ( mb_strlen( $title ) > 50 ) ? mb_substr( $title, 0, 49 ) . '...' : $title;
$html .= '<option value="' . $post_id . '" selected="selected">' . $title . '</option>';
}
}
$html .= '</select></p>';
echo $html;
//==========================================
}
//* Output the HTML for the metabox.
public function vpm_featured_product_callback() {
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'vpm_featured_product_nonce' );
$html = '';
// always array because we have added [] to our <select> name attribute
$feature_sale_options = get_option( 'feature_sale_option_name' ); // Array of All Options
$vpm_featured_product = $feature_sale_options['vpm_featured_product'];
$html .= '<p><select id="vpm_featured_product" name="vpm_featured_product[]" multiple="multiple" style="width:99%;max-width:25em;">';
if( $vpm_featured_product ) {
foreach( $vpm_featured_product as $post_id ) {
$title = get_the_title( $post_id );
// if the post title is too long, truncate it and add "..." at the end
$title = ( mb_strlen( $title ) > 50 ) ? mb_substr( $title, 0, 49 ) . '...' : $title;
$html .= '<option value="' . $post_id . '" selected="selected">' . $title . '</option>';
}
}
$html .= '</select></p>';
echo $html;
echo $vpm_featured_product;
//==========================================
?>
<script>
(function ($) {
'use strict';
$(function () {
//--------------------------------------------------------------------------
// multiple select with AJAX search
$('#vpm_featured_product,#vpm_sale_product').select2({
ajax: {
url: ajaxurl, // AJAX URL is predefined in WordPress admin
dataType: 'json',
delay: 250, // delay in ms while typing when to perform a AJAX search
data: function (params) {
return {
q: params.term, // search query
action: 'getproductsearch' // AJAX action for admin-ajax.php
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
// data is the array of arrays, and each of them contains ID and the Label of the option
$.each( data, function( index, text ) { // do not forget that "index" is just auto incremented value
options.push( { id: text[0], text: text[1] } );
});
}
return {
results: options
};
},
cache: true
},
minimumInputLength: 3 // the minimum of symbols to input before perform a search
});
//----------------------------------------------------------------------------------------
});
})(jQuery);
</script>
<?php
}
}
if ( is_admin() )
$feature_sale = new FeatureSale();
The problem is that these select tags are not using the correct name value:
<select id="vpm_sale_product" name="vpm_sale_product[]"...>
<select id="vpm_featured_product" name="vpm_featured_product[]"...>
And the proper name values are: (based on your register_setting() call)
<select id="vpm_sale_product" name="feature_sale_option_name[vpm_sale_product][]"...>
<select id="vpm_featured_product" name="feature_sale_option_name[vpm_featured_product][]"...>
And although after correcting the above issue, the form data would be saved properly, the fifth parameter (i.e. the menu/page slug) passed to add_submenu_page() should match the fourth parameter passed to add_settings_section() and add_settings_field(), and also the one passed to do_settings_sections(). In your add_submenu_page() call, the menu/page slug is feature-sale, but with the other three functions, you set it to feature-sale-admin.
And using wp_nonce_field() is recommended, but in your case, it's not necessary since you're submitting to wp-admin/options.php. Unless of course, you want to check that prior to WordPress saving the options. But even so, I believe one nonce field is good. :)
I have added multi select meta box to custom post-type it appears good but save only one selection . How to change the code below to save all selected options.
add_action( 'add_meta_boxes', 'add_condition_metaboxes'); function add_scondition_metaboxes() {
add_meta_box('condition', 'Информация спикеров', 'wpt_condition_author', 'condition', 'side', 'default');} function wpt_scondition_author() {
global $post;
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="conditionmeta_noncename" id="conditionmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// Get the author data if its already been entered
$my_dropdown = get_post_meta($post->ID, '_dappcf_i_dropdown', true);
// Echo out the field
$posts = get_posts(array('post_type'=> 'speakers', 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1));
//here you add the HTML of the dropdown you add something like
echo '<p>Select the speaker: <select multiple="yes" name="_dappcf_i_dropdown" class="widefat" style="width:170px">';
foreach ($posts as $post) {
echo '<option value="', $post->ID, '">'.$post->post_title.'</option>'; }
echo '</select>'; } function wpt_save_condition_meta($post_id, $post) {
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['conditionmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
$condition_meta['_dappcf_i_dropdown'] = $_POST['_dappcf_i_dropdown'];
// Add values of $testimonial_meta as custom fields
foreach ($condition_meta as $key => $value) { // Cycle through the $testimonial_meta array!
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn't have a value
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
} } add_action('save_post', 'wpt_save_condition_meta', 1, 2); // save the custom fields
The options are queried from other custom post-type and the number of post can be changed.
I have created one plugin import.php
<?php
function fileupload_process() {
ini_set('memory_limit', '64M');
set_time_limit(0);
$uploadfiles = $_FILES['uploadfiles'];
//echo 'ddd';
// exit;
if (is_array($uploadfiles)) {
//echo 'ram';
//print_r($uploadfiles);
echo $uploadfiles['name'];
// foreach ($uploadfiles as $key => $value) {
foreach ($uploadfiles['name'] as $key => $value) {
// look only for uploaded files
if ($uploadfiles['error'][$key] == 0) {
$filetmp = $uploadfiles['tmp_name'][$key];
if (($handle = fopen($filetmp, "r")) !== FALSE) {
$flag = true;
$songs = explode("\n",file_get_contents($filetmp));
$count = count( $songs );
unset($songs);
echo "Total item count: " . $count . "<BR />";
// typical entry: If You Have To Ask,Red Hot Chili Peppers,0:03:37, Rock & Alternative,1991,on
// using a generous 1000 length - will lowering this actually impact performance in terms of memory allocation?
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// Skip the first entry in the csv containing colmn info
if($flag) {
$flag = false;
echo "<BR />";
$count--;
continue;
}
// insert the current post and relevant info into the database
$currently_processed = process_custom_post($data);
$count--;
}
echo "Done!";
fclose($handle);
}
unlink($filetmp); // delete the temp csv file
}
}
}
} // END: file_upload_process()
function process_custom_post($song) {
global $wpdb;
// Prepare and insert the custom post
$track = (array_key_exists(0, $song) && $song[0] != "" ? $song[0] : 'N/A');
$custom_post = array();
$custom_post['post_type'] = 'songs';
$custom_post['post_status'] = 'publish';
$custom_post['post_title'] = $track;
$post_id = wp_insert_post( $custom_post );
// Prepare and insert the custom post meta
$meta_keys = array();
$meta_keys['artist_name'] = (array_key_exists(1, $song) && $song[1] != "" ? $song[1] : 'N/A');
$meta_keys['song_length'] = (array_key_exists(2, $song) && $song[2] != "" ? $song[2] : 'N/A');
$meta_keys['song_genre'] = (array_key_exists(3, $song) && $song[3] != "" ? $song[3] : 'N/A');
$meta_keys['song_year'] = (array_key_exists(4, $song) && $song[4] != "" ? $song[4] : 'N/A');
$meta_keys['song_month'] = (array_key_exists(5, $song) && $song[5] != "" ? $song[5] : 'N/A');
$meta_keys['sample_playlist'] = (array_key_exists(6, $song) && $song[6] != "" ? $song[6] : '');
$custom_fields = array();
$place_holders = array();
$query_string = "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value) VALUES ";
foreach($meta_keys as $key => $value) {
array_push($custom_fields, $post_id, $key, $value);
$place_holders[] = "('%d', '%s', '%s')";
}
$query_string .= implode(', ', $place_holders);
$wpdb->query( $wpdb->prepare("$query_string ", $custom_fields));
return true;
}// END: process_custom_post()
function import_page () {
//HTML for the import page + the file upload form
if (isset($_POST['uploadfile'])) {
fileupload_process();
}
}
In main.php I do customize the code:
<?php
/*
Plugin Name: csv ram
Plugin URI: http://www.newdreamdatasystems.com
Description: csv ram
Version: 2.0
Author: RAM KUMAR
Author URI: http://www.newdreamdatasystems.com
*/
define('SAVEQUERIES', true);
define( 'MY_PLUGIN_ROOT' , dirname(__FILE__) );
include_once( MY_PLUGIN_ROOT . '/import.php');
$ram = import_page();
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'tools.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
function my_custom_submenu_page_callback() {
$html= <<<RAM
<form action="{$ram}" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="">
<label>upload file<input type="file" name="uploadfiles" id="uploadfiles" /></label>
<label><input type="submit" name="uploadfile" id="uploadfile" value="Submit" /></label>
</form>
RAM;
echo $html;
}
But I have one error:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\try\import.php on line 13..?
How to fix this?
Three main problems:
The function import_page() should be run inside the callback:
function my_custom_submenu_page_callback() {
import_page();
/* etc */
}
Action <form action=""> should be empty, so it goes back to the same plugin page, /wp-admin/tools.php?page=my-custom-submenu-page.
The file field should allow for multiple uploads so this will work foreach ($uploadfiles as $key => $value) and remove the error you're seeing.
<input type="file" name="uploadfiles[]" id="uploadfiles" multiple />
Thinking better, you may not need the multiple attribute, but then adjust the rest of the logic.
But after this adjustments, there are still a bunch of notices and warnings, like Array to string conversion, Undefined index: name and fopen(): Filename cannot be empty.
All this is easily fixed with careful debugging, this is how I found the 3 problems above:
Add printf( '<pre>%s</pre>', print_r( $INSPECT_VAR, true ) ); to go inspecting the problematic variables.
My site's theme has been working fine for a few days when suddendly without any coding changes I now am getting this error:
Parse error: syntax error, unexpected end of file in /home/henrysst/public_html/wp-content/themes/bettycommerce/includes/pro_framework/admin.php on line 812
I have made no changes to the theme, and it was working fine before (Apart from Revolution slider not working)
here is that line that is pulling up the error:
}
add_action('upfw_admin_header_links','upfw_default_header_links');
Here is also the link to the site, if its of any help: http://henrysstuff.co.uk/
Thank you in advance for any help you can provide.
FULL CODE:
<?php
/******
** Pro Bones Framework Version
*************************************/
define('UPTHEMES_VER', '1.0.0');
/******
** Theme init hook
*************************************/
function upfw_theme_init(){
do_action('upfw_theme_init');
}
/******
** Admin init hook
*************************************/
function upfw_admin_init(){
do_action('upfw_admin_init');
}
/******
** Initialization adds hooks to
** two places: theme and admin
*************************************/
function upfw_init(){
if( is_admin() ):
add_action('after_setup_theme','upfw_admin_init');
else:
add_action('after_setup_theme','upfw_theme_init');
endif;
}
add_action('after_setup_theme','upfw_init',1);
/******
** Set up theme data
*************************************/
function upfw_generate_theme_data(){
$get_up_theme = get_theme_data(TEMPLATEPATH .'/style.css');
$theme_title = $get_up_theme['Title'];
$theme_shortname = strtolower(preg_replace('/ /', '_', $theme_title));
$theme_version = $get_up_theme['Version'];
$theme_template = $get_up_theme['Template'];
define('UPTHEMES_NAME', $theme_title);
define('TEMPLATENAME', $theme_title);
define('UPTHEMES_SHORT_NAME', $theme_shortname);
define('UPTHEMES_THEME_VER', $theme_version);
if( file_exists(TEMPLATEPATH.'/includes/pro_framework/admin.php') ):
define( 'THEME_PATH' , TEMPLATEPATH );
define( 'THEME_DIR' , get_template_directory_uri() );
elseif( file_exists(STYLESHEETPATH.'/includes/pro_framework/admin.php') ):
define( 'THEME_PATH' , STYLESHEETPATH );
define( 'THEME_DIR' , get_stylesheet_directory_uri() );
endif;
// Detect child theme info
if(STYLESHEETPATH != TEMPLATEPATH):
$get_up_theme = get_theme_data(STYLESHEETPATH .'/style.css');
$theme_title = $get_up_theme['Title'];
$theme_shortname = strtolower(preg_replace('/ /', '_', $theme_title));
$theme_version = $get_up_theme['Version'];
$theme_template = $get_up_theme['Template'];
define('CHILD_NAME', $theme_title);
define('CHILD_SHORT_NAME', $theme_shortname);
define('CHILD_THEME_VER', $theme_version);
define('CHILD_PATH', STYLESHEETPATH);
endif;
}
add_action('upfw_admin_init','upfw_generate_theme_data',1);
add_action('upfw_theme_init','upfw_generate_theme_data',1);
/******
** Upload error msg
*************************************/
function upfw_upload_error(){
$uploads_dir = wp_upload_dir();
$error = $uploads_dir['error'];
echo '<div id="message" class="error"><p>' . $error . '</p></div>';
return false;
}
/******
** Upload folder permissions
** error msg
*************************************/
function upfw_permissions_error(){
echo '<div id="message" class="error"><p>' . __('It looks like your uploads folder does not have proper permissions. Please set your uploads folder, typically located at [wp-install]/wp-content/uploads/, to 775 or greater.', MOJO_TEXTDOMAIN) . '</p></div>';
return false;
}
/******
** Upload folder created
** success msg
*************************************/
function upfw_uploads_folder_created(){
$uploads_dir = wp_upload_dir();
$base_upload_dir = $uploads_dir['basedir']."/upfw";
echo '<div id="message" class="update-nag">' . __('Pro Affiliate Framework uploads folder created successfully! Your new folder is located at '.$base_upload_dir.'.', MOJO_TEXTDOMAIN) . '</div>';
return false;
}
/******
** Set the uploads directory
** for media from themes
*************************************/
function upfw_set_uploads_dir(){
$uploads_dir = wp_upload_dir();
if( $uploads_dir['error'] )
add_action( 'admin_notices', 'upfw_upload_error', 1, 1 );
else{
$base_upload_dir = $uploads_dir['basedir']."/upfw";
$base_upload_url = $uploads_dir['baseurl']."/upfw";
if(!is_dir($base_upload_dir) ){
if( !is_writeable( $uploads_dir['basedir'] ) )
add_action( 'admin_notices', 'upfw_permissions_error', 1, 1 );
else{
$oldumask = umask(0);
#mkdir($base_upload_dir, 0775);
umask($oldumask);
if( is_writeable( $base_upload_dir ) )
add_action( 'admin_notices', 'upfw_uploads_folder_created',1 , 1 );
}
}
}
if($base_upload_dir)
define('UPFW_UPLOADS_DIR',$base_upload_dir, true);
if($base_upload_url)
define('UPFW_UPLOADS_URL',$base_upload_url, true);
}
add_action('upfw_theme_init','upfw_set_uploads_dir',2);
add_action('upfw_admin_init','upfw_set_uploads_dir',2);
/******
** Gentlemen, start your engines
*************************************/
function upfw_engines_init(){
require_once('library/options/options.php');
require_once('library/widgets/dashboard.php');
if( !defined('DISABLE_LAYOUT_ENGINE') )
require_once('library/engines/layout-engine.php');
if( !defined('DISABLE_STYLE_ENGINE') )
require_once('library/engines/style-engine.php');
if(function_exists('upfw_dbwidget_setup'))
add_action('wp_dashboard_setup', 'upfw_dbwidget_setup' );
if(function_exists('default_theme_layouts'))
add_action('init','default_theme_layouts',1);
}
add_action('upfw_theme_init','upfw_engines_init',10);
add_action('upfw_admin_init','upfw_engines_init',10);
/******
** Conditional to test if we're on
** an Pro Affiliate Framework page
*************************************/
function is_upthemes_page(){
if(is_admin()):
if(isset($_REQUEST['page']))$page = $_REQUEST['page'];
if(!empty($page)):
if( $page =='proframework' || $page=='proframework-buy' || $page =='proframework-docs' ):
return true;
else:
return false;
endif;
endif;
endif;
}
/******
** Add CSS and Javascript includes
*************************************/
function upfw_queue_scripts_styles(){
$upthemes = THEME_DIR.'/includes/pro_framework/';
wp_enqueue_style('up_framework',$upthemes."css/pro_framework.css");
//Check if theme-options/style.css exists and load it
if(file_exists(THEME_PATH ."/theme-options/style.css")):
wp_enqueue_style('theme_options',THEME_DIR."/theme-options/style.css");
endif;
wp_enqueue_style('farbtastic');
wp_enqueue_script('jquery.history',
$upthemes."js/jquery.history.js",
array('jquery'));
wp_enqueue_script('jquery.color',
$upthemes."js/jquery.color.js",
array('jquery'));
wp_enqueue_script('ajaxupload',
$upthemes."js/ajaxupload.js",
array('jquery'));
wp_enqueue_script('upfw',
$upthemes . "js/pro_framework.js",
array('farbtastic','jquery.history','ajaxupload'));
/* For Typography Engine */
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-widget');
wp_enqueue_script('jquery-ui-mouse');
wp_enqueue_script('jquery-ui-slider', get_bloginfo('template_directory').'/includes/pro_framework/js/jquery.ui.slider.js', array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse'));
wp_enqueue_style('up-slider', get_bloginfo('template_directory').'/includes/pro_framework/css/ui-themes/smoothness/style.css');
}
if( is_admin() && is_upthemes_page() ):
add_action('upfw_theme_init','upfw_queue_scripts_styles',40);
add_action('upfw_admin_init','upfw_queue_scripts_styles',40);
endif;
/******
** Show gallery images
*************************************/
function show_gallery_images(){
global $wpdb;
$theme = THEME_DIR;
$path = UPFW_UPLOADS_DIR."/";
$dir_handle = #opendir($path) or die("Unable to open folder. Please make sure your uploads folder exists and has permissions of 775 or greater.");
while (false !== ($file = readdir($dir_handle))):
if($file == "index.php") continue;
if($file == ".") continue;
if($file == "..") continue;
if($file == "list.php") continue;
if($file == "Thumbs.db") continue;
$list .= '<a class="preview" href="'. UPFW_UPLOADS_URL . "/". $file . '"><img src="' . UPFW_UPLOADS_URL . "/" . $file . '" /></a>';
endwhile;
$list .= '<div class="clear"></div>';
echo $list;
closedir($dir_handle);
die();
}
/**
* Get current template context
*
* Returns a string containing the context of the
* current page template. This string is useful for several
* purposes, including applying an ID to the HTML
* body tag, and adding a contextual $name to calls
* to get_header(), get_footer(), get_sidebar(),
* and get_template_part_file(), in order to
* facilitate Child Themes overriding default Theme
* template part files.
*
* #param none
* #return string current page template context
*/
function upfw_get_template_context() {
$context = 'index';
if ( is_front_page() ) {
// Front Page
$context = 'front-page';
} else if ( is_date() ) {
// Date Archive Index
$context = 'date';
} else if ( is_author() ) {
// Author Archive Index
$context = 'author';
} else if ( is_category() ) {
// Category Archive Index
$context = 'category';
} else if ( is_tag() ) {
// Tag Archive Index
$context = 'tag';
} else if ( is_tax() ) {
// Taxonomy Archive Index
$context = 'taxonomy';
} else if ( is_archive() ) {
// Archive Index
$context = 'archive';
} else if ( is_search() ) {
// Search Results Page
$context = 'search';
} else if ( is_404() ) {
// Error 404 Page
$context = '404';
} else if ( is_attachment() ) {
// Attachment Page
$context = 'attachment';
} else if ( is_single() ) {
// Single Blog Post
$context = 'single';
} else if ( is_page() ) {
// Static Page
$context = 'page';
} else if ( is_home() ) {
// Blog Posts Index
$context = 'home';
}
return $context;
}
add_action('wp_ajax_show_gallery_images','show_gallery_images');
/******
** Create Framework Options Pages
*************************************/
function upfw_create_options_tabs(){
// Discover Options Files and Create Tabs Array
if( is_admin() ):
$path = THEME_PATH."/theme-options/";
$directory = #opendir($path) or wp_die("Cannot open theme-options folder in the ".UPTHEMES_NAME." folder.");
while (false !== ($file = readdir($directory))) {
if(!preg_match('/_/', $file)) continue;
if(preg_match('/_notes/', $file)) continue;
if(preg_match('/.DS/', $file)) continue;
//Take the extension off
$file = explode('.php', $file);
//Separate the ordinal
$file = explode('_', $file[0]);
$order = $file[1];
//Define the shortname
$shortname = $file[0];
//Define the title
$file = explode('-', $shortname);
$title = '';
foreach ($file as $part):
$title .= $part." ";
endforeach;
$title = ucwords($title);
//Add tab to array
global $up_tabs;
$up_tabs[$order] = array(trim($title) => $shortname);
$title = '';
}
closedir($directory);
//Sort tab order
global $up_tabs;
ksort($up_tabs);
endif;
}
add_action('upfw_admin_init','upfw_create_options_tabs',50);
/******
** Install default theme options
** if not already set
*************************************/
function upfw_set_defaults(){
if( ! get_option( 'up_themes_'.UPTHEMES_SHORT_NAME) && ( ! isset( $_GET['page'] ) || 'proframework' != $_GET['page'] ) ) :
//Redirect to options page where defaults will automatically be set
header('Location: '.get_bloginfo('url').'/wp-admin/admin.php?page=proframework');
exit;
endif;
}
add_action('upfw_theme_activation', 'upfw_set_defaults',2);
/******
** Set up global theme options
*************************************/
function upfw_setup_theme_options(){
$up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
global $up_options;
//Check if options are stored properly
if( isset($up_options_db) && is_array($up_options_db) ):
add_action('upfw_theme_init','upfw_setup_theme_options',100);
add_action('upfw_admin_init','upfw_setup_theme_options',100);
/******
** Bootstrap static framework pages
*************************************/
function upthemes_admin_home() {require_once('home.php');}
function upthemes_admin_docs(){require_once('docs.php');}
/******
** Activate Pro Affiliate Framework admin
*************************************/
function upfw_upthemes_admin() {
$name = __('My Options', MOJO_TEXTDOMAIN);
$theme_options_icon = apply_filters('theme_options_icon',THEME_DIR.'/includes/pro_framework/images/upfw_ico_up_16x16.png');
add_menu_page($name, $name, 'edit_theme_options', 'proframework', 'upthemes_admin_home', $theme_options_icon, 59);
//Create tabbed pages from array
global $up_tabs;
if( is_array( $up_tabs ) ):
foreach ($up_tabs as $tab):
foreach($tab as $title => $shortname):
add_submenu_page('proframework', $title, $title, 'edit_theme_options', 'proframework#/'.$shortname, 'upthemes_admin_'.$shortname);
endforeach;
endforeach;
endif;
//Static subpages
// add_submenu_page('proframework', __('Documentation', MOJO_TEXTDOMAIN), __('Documentation', MOJO_TEXTDOMAIN), 'edit_theme_options', 'proframework-docs', 'upthemes_admin_docs');
}
add_action('admin_menu', 'upfw_upthemes_admin',2);
/******
** Find default options
*************************************/
function find_defaults($options){
global $up_defaults;
print_r($options);
}
/******
** Render theme options
*************************************/
function render_options($options){
//Check if theme options set
global $default_check;
global $default_options;
global $attr;
$attr = '';
if(!$default_check):
foreach($options as $option):
if($option['type'] != 'image'):
$default_options[$option['id']] = $option['value'];
else:
$default_options[$option['id']] = $option['url'];
endif;
endforeach;
$update_option = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
if(is_array($update_option)):
$update_option = array_merge($update_option, $default_options);
update_option('up_themes_'.UPTHEMES_SHORT_NAME, $update_option);
else:
update_option('up_themes_'.UPTHEMES_SHORT_NAME, $default_options);
endif;
endif;
foreach ($options as $value) {
//Check if there are additional attributes
if ( isset( $value['attr'] ) && is_array( $value['attr'] ) ):
$i = $value['attr'];
//Convert array into a string
foreach($i as $k => $v):
$attr .= $k.'="'.$v.'" ';
endforeach;
endif;
//Determine the type of input field
switch ( $value['type'] ) {
//Render Text Input
case 'text': upfw_text_field($value,$attr);
break;
//Render Custom User Text Inputs
case 'text_list': upfw_text_list($value,$attr);
break;
//Render textarea options
case 'textarea': upfw_textarea($value,$attr);
break;
//Render select dropdowns
case 'select': upfw_select($value,$attr);
break;
//Render multple selects
case 'multiple': upfw_multiple($value,$attr);
break;
//Render checkboxes
case 'checkbox': upfw_checkbox($value,$attr);
break;
//Render color picker
case 'color': upfw_color($value,$attr);
break;
//Render upload image
case 'image': upfw_image($value,$attr);
break;
//Render upload image
case 'logo': upfw_logo($value,$attr);
break;
//Render category dropdown
case 'category': upfw_category($value,$attr);
break;
//Render categories multiple select
case 'categories': upfw_categories($value,$attr);
break;
//Render offer dropdown
case 'offer': upfw_offer($value,$attr);
break;
//Render sales letter dropdown
case 'sales_letter': upfw_sales_letter($value,$attr);
break;
//Render squeeze page dropdown
case 'squeeze': upfw_squeeze($value,$attr);
break;
//Render page dropdown
case 'page': upfw_page($value,$attr);
break;
//Render pages muliple select
case 'pages': upfw_pages($value,$attr);
break;
//Render Form Button
case 'submit': upfw_submit($value,$attr);
break;
//Render taxonomy multiple select
case 'taxonomy': upfw_taxonomy($value,$attr);
break;
//Render Style Selector
case 'styles': upfw_style($value,$attr);
break;
//Render Form Button
case 'button': upfw_button($value,$attr);
break;
//Render Text Input
case 'divider': upfw_divider($value,$attr);
break;
//Render Layouts
case 'layouts': upfw_layouts($value,$attr);
break;
default:
break;
}
$attr = '';
}
}
if(is_admin() && is_upthemes_page()) add_action( 'upfw_admin_init','upfw_save_options', 3 );
function upfw_save_options(){
/* ----------------------- Form Security Check -------------------------- */
if(isset($_POST['_wpnonce'])):
//Check if submitted from this domain
check_admin_referer();
//Verify Form Nonce
if (!wp_verify_nonce($_POST['_wpnonce'], 'save_upthemes') )
wp_die('Security exception detected, please try again.');
exit;
endif;
/* ------------------Import/Export Functions ----------------------- */
//Restore Previous Options
global $export_message;
if(isset($_POST['up_restore'])):
$current = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
$backup = get_option('up_themes_'.UPTHEMES_SHORT_NAME.'_backup');
update_option('up_themes_'.UPTHEMES_SHORT_NAME.'_backup', $current);
update_option('up_themes_'.UPTHEMES_SHORT_NAME, $backup);
$export_message = "<p class='import'>" . __("Everything's back to normal now!", MOJO_TEXTDOMAIN) . "</p>";
endif;
//Restore Defaults
if(isset($_POST['up_defaults'])):
$current = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
update_option('up_themes_'.UPTHEMES_SHORT_NAME.'_backup', $current);
delete_option('up_themes_'.UPTHEMES_SHORT_NAME);
$export_message = "<p class='import'>" . __("Default options restored!", MOJO_TEXTDOMAIN) . "<span><form method='post' action=''><input class='up_restore' type='submit' name='up_restore' value='" . __("Click Here to Undo", MOJO_TEXTDOMAIN) . "'></form></span></p>";
endif;
/* ------------------------- Import Options Code ------------------------------- */
if(isset($_POST['up_import']) && isset($_POST['up_import_code'])):
$import = $_POST['up_import_code'];
$import = base64_decode($import);
$import = explode('~~', $import);
//Check if code is legitimate
if(count($import) == 2):
$option_name = $import[0];
$options = explode('||', $import[1]);
foreach ($options as $option):
$option = explode('|', $option);
global $new_options;
$new_options[$option[0]] = preg_replace('/"/', '\'', stripslashes($option[1]));
endforeach;
$current_option = get_option($option_name);
update_option($option_name.'_backup', $current_option);
update_option($option_name, $new_options);
$export_message = "<p class='import'>" . __("Options Code Import Successful!", MOJO_TEXTDOMAIN) . "<span><form method='post' action=''><input class='up_restore' type='submit' name='up_restore' value='" . __("Click Here to Undo", MOJO_TEXTDOMAIN) . "'></form></span></p>";
else:
$export_message = "<p class='import'>" . __("Oops! Something went wrong. <span>Try pasting your import code again.</span>", MOJO_TEXTDOMAIN) . "</p>";
endif;
endif;
/* ------------------------- Save Theme Options ------------------------------- */
if(isset($_POST['up_save'])):
$posts = $_POST;
foreach($posts as $k => $v):
//Check if option is array (mulitple selects)
if(is_array($v)):
//Check if array is empty
$check = 0;
foreach($v as $key => $value):
if($value != ''):
$check++;
endif;
endforeach;
//If array is not empty
if($check > 0 ):
//Remove empty array elements
$post[$k] = array_filter($v);
else:
$post[$k] = '';
endif;
$check = 0;
else:
//Remove slashes
$post[$k] = preg_replace('/"/', '\'', stripslashes($v));
endif;
endforeach;
//Add options array to wp_options table
update_option('up_themes_'.UPTHEMES_SHORT_NAME, $post);
endif;
/* ---------------------- Default Options Functions ----------------- */
global $default_check;
global $default_options;
$option_check = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
if($option_check):
$default_check = true;
else:
$default_check = false;
endif;
}
/******
** Remove Ugly First Link in
** WP Sidebar Menu
*************************************/
function remove_ugly_first_link(){ ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('li#toplevel_page_upthemes li.wp-first-item').remove();
});
</script>
<?php }
if( is_admin() )
add_action("admin_head","remove_ugly_first_link");
/******
** RSS URL: rss('return') will return
** the value and not echo it.
*************************************/
function upfw_rss($i = ''){
global $up_options;
if($up_options->feedburner):
$rss = "http://feeds.feedburner.com/".$up_options->feedburner;
else:
$rss = get_bloginfo_rss('rss2_url');
endif;
if($i == 'return'): return $rss; else: echo $rss; endif;
}
/******
** RSS Subscribe URL: rss_email('return')
** will return the value and not echo it.
*************************************/
function upfw_rss_email($i = ''){
global $up_options;
if($up_options->feedburner):
$rssemail = "http://www.feedburner.com/fb/a/emailverifySubmit?feedId=" . $up_options->feedburner;
else:
$rssemail = "#";
endif;
if($i == 'return'): return $rssemail; else: echo $rssemail; endif;
}
/******
** Admin header hook
*************************************/
function upfw_admin_header(){
do_action('upfw_admin_header');
}
/******
** Open admin header
*************************************/
function upfw_admin_header_open(){ ?>
<div id="up_header" class="polish"><?php
}
add_action('upfw_admin_header','upfw_admin_header_open',1);
/******
** Set admin header title
*************************************/
function upfw_admin_header_title(){ ?>
<div id="icon-upfw" class="icon32 icon32-upfw"></div>
<h2><?php _e("", MOJO_TEXTDOMAIN); ?></h2> <?php
}
add_action('upfw_admin_header','upfw_admin_header_title',100);
/******
** Create admin header links
*************************************/
function upfw_admin_header_links(){ ?>
<ul id="up_topnav">
<?php do_action('upfw_admin_header_links'); ?>
</ul><!-- /#up_topnav --><?php
}
add_action('upfw_admin_header','upfw_admin_header_links',50);
/******
** Close admin header
*************************************/
function upfw_admin_header_close(){ ?>
<div class="clear"></div>
</div><!-- /#up_header --><?php
}
add_action('upfw_admin_header','upfw_admin_header_close',500);
/******
** Add default header links
*************************************/
function upfw_default_header_links(){ ?>
<li class="documentation"><?php _e("MOJO-Themes Item Page", MOJO_TEXTDOMAIN); ?></li>
<li class="support"><a target="_blank" href="http://docs.mojoness.com/"><?php _e("Support", MOJO_TEXTDOMAIN); ?></a></li>
<?php
}
add_action('upfw_admin_header_links','upfw_default_header_links');
sorry , just add ?> at last.
try to change it to
add_action('upfw_admin_header','upfw_admin_header_links',50);
Holding-Pattern-Theme
Looks like a missing } for function upfw_setup_theme_options() declaration (line 411).
EDIT:
function upfw_setup_theme_options(){
$up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
global $up_options;
//Check if options are stored properly
if( isset($up_options_db) && is_array($up_options_db) ):
# missing part start
//Check array to an object
foreach ($up_options_db as $k => $v) {
$up_options -> {$k} = $v;
}
else:
do_action('upfw_theme_activation');
endif;
}
#missing part end
from https://github.com/LiftUX/Holding-Pattern-Theme/blob/master/admin/admin.php
This error was happening on my local env but not on other's computers
Make sure you close the PHP tag correctly:
<?php } ?>
In my particular case:
<?php if( $condition ){ ?>
<div> content </div>
<? } ?>
That last block: <? } ?> was missing the ?php close tag.