$input_value) { if($default = aa_get_option('aa_default_' . $input_key)) { $aa_settings['custom_field_inputs'][$input_key]['default'] = $default; } } //Add custom fields add_action( 'admin_head-post.php', 'aa_create_custom_fields_box' ); add_action( 'admin_head-post-new.php', 'aa_create_custom_fields_box' ); //Save custom fields add_action('save_post', 'aa_save_custom_fields', 10, 2); //Add CSS wp_register_style('aa_css', plugins_url('auctionaffiliate.css', __FILE__)); wp_enqueue_style('aa_css'); //Add JS wp_register_script('aa_js', plugins_url('auctionaffiliate.js', __FILE__), array('jquery')); wp_enqueue_script('aa_js'); //Thickbox add_thickbox(); } } add_action('admin_init', 'aa_admin_init'); /** * ======================================================== * ================= CUSTOM FIELDS ======================== * ======================================================== */ /** * Create the custom fields box */ function aa_create_custom_fields_box() { global $aa_settings; foreach(array('post', 'page') as $post_type) { add_meta_box('aa-custom-fields', $aa_settings['plugin_name'], 'aa_create_custom_field_form', $post_type, 'normal', 'high'); } } /** * Create the custom field form */ function aa_create_custom_field_form() { global $post, $aa_settings; echo '
' . "\n"; //Tab links echo '' . "\n"; //Lister tool echo '
' . "\n"; echo '
' . "\n"; echo '

Use these options to specify which eBay items to display within your page/post. Add the following shortcode within your content editor to specify where the items will appear:

[' . $aa_settings['shortcode'] . ' tool="lister"]

' . "\n"; echo '

Multiple shortcodes can be added, see the plugin help section for more information:

' . "\n"; echo ' Plugin Help' . "\n"; echo '
' . "\n"; $current_group = false; $count = 0; foreach($aa_settings['custom_field_inputs'] as $field) { if($field['lister_param']) { //Prefix for this tool $field['name'] = aa_prefix($field['name'], 'lister', '_'); $field['id'] = aa_prefix($field['id'], 'lister', '-'); $group = $aa_settings['custom_field_groups'][$field['group']]; //Output group? if($current_group != $group) { //Close previous fieldset? if($current_group !== false) { echo '
' . "\n"; echo ' ' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } //Post meta? $set_value = aa_get_post_meta_single($post->ID, $field['name']); aa_create_param_input($field, $count, $set_value); $count++; } } echo '
' . "\n"; echo '
' . "\n"; echo '
' . "\n"; //Banner tool echo ' ' . "\n"; echo ' ' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } //Post meta? $set_value = aa_get_post_meta_single($post->ID, $field['name']); aa_create_param_input($field, $count, $set_value); $count++; } } echo '
' . "\n"; echo '
' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo '' . "\n"; } /** * Create the custom fields inputs */ function aa_create_param_input($field, $count = false, $set_value = false) { $out = ''; //Do we have a default? if(! array_key_exists('default', $field)) { $field['default'] = false; } //Container $alt = ($count !== false && $count % 2) ? ' alt' : ''; $out .= '
' . "\n"; /* //Required $required = ''; if($field['parameter_required']) { $required = ' *'; } */ //Tip $tip = ''; if($field['tip']) { $tip = ' ?'; } //Label $out .= ' ' . "\n"; $out .= '
' . "\n"; //Default type if(! array_key_exists('type', $field)) { $field['type'] = 'text'; } switch($field['type']) { case 'select' : $out .= ' ' . "\n"; break; case 'checkbox' : //Value submitted? $checked = false; if($set_value && ($set_value == 'true' || $set_value == $field['value'])) { $checked = true; } elseif($field['default'] == 'true') { $checked = true; } $value = ($field['value']) ? $field['value'] : 'true'; $out .= ' $description) { //Value submitted? if(! $checked = ($set_value == $value)) { $checked = $value == $field['default']; } $out .= '
' . "\n"; $out .= ' ' . "\n"; $out .= '
' . "\n"; } break; case 'text' : default : $out .= ' ' . "\n"; echo 'Plugin Help' . "\n"; echo '

' . $aa_settings['plugin_name'] . '

' . "\n"; echo '
' . "\n"; settings_fields('aa_options'); do_settings_sections('aa'); echo ' ' . "\n"; echo '
' . "\n"; echo ' ' . "\n"; echo '
' . "\n"; } /** * Define settings */ function aa_admin_settings(){ //Permissions if(current_user_can('manage_options')) { global $aa_settings; register_setting('aa_options', 'aa_options', 'aa_options_validate'); add_settings_section('aa_defaults', 'Default Settings', 'aa_defaults_text', 'aa'); //Affiliate add_settings_section('aa_defaults_affiliate', 'Affiliate Defaults', 'aa_defaults_affiliate_text', 'aa'); add_settings_field('aa_default_eSite', 'Default eBay Site', 'aa_default_eSite_setting', 'aa', 'aa_defaults_affiliate'); add_settings_field('aa_default_eCampID', 'Default EPN Campaign ID', 'aa_default_eCampID_setting', 'aa', 'aa_defaults_affiliate'); add_settings_field('aa_default_eCustomID', 'Default EPN Custom ID', 'aa_default_eCustomID_setting', 'aa', 'aa_defaults_affiliate'); //Lister add_settings_section('aa_defaults_lister', 'Item Lister Defaults', 'aa_defaults_lister_text', 'aa'); add_settings_field('aa_default_aTheme', 'Default Theme', 'aa_default_aTheme_setting', 'aa', 'aa_defaults_lister'); add_settings_field('aa_default_aColourP', 'Default Primary Colour', 'aa_default_aColourP_setting', 'aa', 'aa_defaults_lister'); add_settings_field('aa_default_aColourS', 'Default Secondary Colour', 'aa_default_aColourS_setting', 'aa', 'aa_defaults_lister'); add_settings_field('aa_default_aColourB', 'Default Background Colour', 'aa_default_aColourB_setting', 'aa', 'aa_defaults_lister'); } } add_action('admin_init', 'aa_admin_settings'); /** * Text to accompany default settings section */ function aa_defaults_text() { echo '

The settings below enable you to specify default preferences, saving you from entering them each time when adding ' . $aa_settings['plugin_name'] . ' to your pages or posts. Defaults can easily be overridden on a page-by-page basis.

' . "\n"; echo '

Hover over the question marks for an explanation of each setting, or click the Plugin Help link for further information.

' . "\n"; } /** * Text to accompany affiliate defaults section */ function aa_defaults_affiliate_text() { echo '

' . "\n"; } /** * Output eBay site setting */ function aa_default_eSite_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Output default campaign setting */ function aa_default_eCampID_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Output default custom ID setting */ function aa_default_eCustomID_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Text to accompany affiliate defaults section */ function aa_defaults_lister_text() { echo '

' . "\n"; } /** * Output default theme setting */ function aa_default_aTheme_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Output default campaign setting */ function aa_default_aColourP_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Output default campaign setting */ function aa_default_aColourS_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Output default campaign setting */ function aa_default_aColourB_setting() { global $aa_settings; $options = get_option('aa_options'); echo '' . "\n"; echo '?' . "\n"; } /** * Validate our options */ function aa_options_validate($input) { $output['aa_default_eSite'] = trim($input['aa_default_eSite']); $output['aa_default_aTheme'] = trim($input['aa_default_aTheme']); $output['aa_default_eCampID'] = trim($input['aa_default_eCampID']); $output['aa_default_eCustomID'] = trim($input['aa_default_eCustomID']); $output['aa_default_aColourP'] = trim($input['aa_default_aColourP']); $output['aa_default_aColourS'] = trim($input['aa_default_aColourS']); $output['aa_default_aColourB'] = trim($input['aa_default_aColourB']); return $output; } /** * Get plugin options */ function aa_get_option($option_key) { $options = get_option('aa_options'); if(is_array($options) && array_key_exists($option_key, $options)) { return $options[$option_key]; } else { return false; } } function an_admin_notice() { echo '
The Auction Affiliate service is being shut down on the 20th May 2015. Please migrate away from this plugin before then to avoid disruption (more information here)
'; } add_action('admin_notices', 'an_admin_notice');