Changeset 705928
- Timestamp:
- 04/30/2013 02:16:09 PM (13 years ago)
- Location:
- call-to-action
- Files:
-
- 9 added
- 4 edited
-
tags/1.3 (added)
-
tags/1.3/call-to-action-admin.php (added)
-
tags/1.3/call-to-action-display.php (added)
-
tags/1.3/call-to-action-functions.php (added)
-
tags/1.3/call-to-action.php (added)
-
tags/1.3/readme.txt (added)
-
tags/1.3/screenshot-1.png (added)
-
tags/1.3/screenshot-2.png (added)
-
tags/1.3/screenshot-3.png (added)
-
trunk/call-to-action-admin.php (modified) (1 diff)
-
trunk/call-to-action-display.php (modified) (3 diffs)
-
trunk/call-to-action.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
call-to-action/trunk/call-to-action-admin.php
r319751 r705928 122 122 return $columns; 123 123 } 124 125 function ctaw_display_options(){ 126 return array( 127 '_is_all_ctaw' => 'Every Page', 128 '_is_front_ctaw' => 'Static Front Page', 129 '_is_page_ctaw' => 'Single Page', 130 '_is_home_ctaw' => 'Blog Page', 131 '_is_single_ctaw' => 'Single Post', 132 '_is_archive_ctaw' => 'Archive', 133 '_is_author_ctaw' => 'Author Archive', 134 '_is_404_ctaw' => '404 Page', 135 '_is_search_ctaw' => 'Search Page' 136 ); 137 } 138 // Meta box 139 function ctaw_add_meta_box() { 140 add_meta_box('ctaw-buttons-meta', __('Call To Action Display', 'ctaw'), 'ctaw_metabox_admin', 'ctaw', 'side'); 141 } 142 143 function ctaw_metabox_admin() { 144 global $post; 145 $display_options = ctaw_display_options(); 146 147 $default_content = ""; 148 $default_content .= '<input type="hidden" name="ctaw_settings_noncename" id="ctaw_settings_noncename" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />'; 149 $default_content .= '<ul id="inline-sortable">'; 150 foreach ($display_options as $ctaw_display=>$ctaw_name) { 151 $default_content .= '<li class="ui-state-default"><label class="selectit"><input value="1" type="checkbox" name="'.$ctaw_display.'" id="post-share-' . $ctaw_display . '"' . checked(get_post_meta($post->ID, $ctaw_display, true), 1, false) . '/> <span>' . __($ctaw_name) . '</span></label></li>'; 152 } 153 $default_content .= '</ul>'; 154 echo $default_content; 155 } 156 157 //============================================= 158 // On save post, update post meta 159 //============================================= 160 function ctaw_admin_process($post_ID) { 161 if (!isset($_POST['ctaw_settings_noncename']) || !wp_verify_nonce($_POST['ctaw_settings_noncename'], plugin_basename(__FILE__))) { 162 return $post_ID; 163 } 164 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 165 return $post_ID; 166 167 if ('page' == $_POST['post_type']) { 168 if (!current_user_can('edit_page', $post_ID)) 169 return $post_ID; 170 } else { 171 if (!current_user_can('edit_post', $post_ID)) 172 return $post_ID; 173 } 174 175 $ctawmetaarray = array(); 176 $ctawmetaarray_text = ""; 177 178 if (isset($_POST['hide_alert']) && ($_POST['hide_alert'] > 0)) { 179 array_push($ctawmetaarray, $_POST['hide_alert']); 180 } 181 if (isset($_POST['ctaw_text']) && ($_POST['ctaw_text'] != "")) { 182 $ctawmetaarray_text = $_POST['ctaw_text']; 183 } 184 if (isset($_POST['ctaw_buttons'])) { 185 foreach ($_POST['ctaw_buttons'] as $button) { 186 if (($button > 0)) { 187 array_push($ctawmetaarray, $button); 188 } 189 $formid++; 190 } 191 } 192 $ctawmeta = implode(',', $ctawmetaarray); 193 194 if (!wp_is_post_revision($post_ID) && !wp_is_post_autosave($post_ID)) { 195 $display_options = ctaw_display_options(); 196 foreach ($display_options as $ctaw_display=>$ctaw_name) { 197 if (isset($_POST[$ctaw_display]) && $_POST[$ctaw_display] != ''){ 198 update_post_meta($post_ID, $ctaw_display, 1); 199 } else { 200 update_post_meta($post_ID, $ctaw_display, 0); 201 } 202 } 203 } 204 } 124 205 ?> -
call-to-action/trunk/call-to-action-display.php
r319751 r705928 1 1 <?php 2 function ctaw_display_action($before_widget, $after_widget, $before_title, $after_title, $hide_title = false){ 3 $current_categories = array(); 4 $possible_actions = array(); 5 $possible_titles = array(); 6 $alt_actions = array(); 7 $alt_titles = array(); 8 9 //Get Parent Post Cateogires 10 global $post; 11 $categories = get_the_category($post->ID); 12 //Set up category names in an array 13 foreach ($categories as $category) { 14 array_push($current_categories,$category->category_nicename); 15 } 16 17 //Get all calls to action 18 $args = array('post_type' => 'ctaw'); 19 $ctaws = get_posts($args); 20 foreach ($ctaws as $ctaw) { 21 $action_categories = array(); 22 setup_postdata($ctaw); 23 //Get call to action categories 24 $ctaw_cats = get_the_category($ctaw->ID); 25 //Set call to action category names in an array 26 foreach ($ctaw_cats as $ctaw_cat){ 27 array_push($action_categories,$ctaw_cat->category_nicename); 28 } 29 // either populate an array of possible actions or display an alternative action if page has no categories 30 if(count($action_categories)==0){ 31 array_push($alt_actions,array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 32 }else if (array_intersect($current_categories, $action_categories)){ 33 array_push($possible_actions,array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 34 } 35 } 36 //display results 2 function ctaw_display_action($before_widget, $after_widget, $before_title, $after_title, $hide_title = false) { 3 $current_categories = array(); 4 $possible_actions = array(); 5 $possible_titles = array(); 6 $alt_actions = array(); 7 $alt_titles = array(); 37 8 38 if(count($possible_actions)>0){ 39 $rand_key = array_rand($possible_actions,1); 40 $ctaw_id = $possible_actions[$rand_key][0]; 41 $ctaw_title = $possible_actions[$rand_key][1]; 42 $ctaw_content = $possible_actions[$rand_key][2]; 43 } else { 44 $rand_key = array_rand($alt_actions,1); 45 $ctaw_id = $alt_actions[$rand_key][0]; 46 $ctaw_title = $alt_actions[$rand_key][1]; 47 $ctaw_content = $alt_actions[$rand_key][2]; 48 } 49 50 $page = get_option('siteurl'); 51 $page = get_page_link(); 52 $symbol = (preg_match('/\?/', $page)) ? '&' : '?'; 53 $ctaw_content = str_replace('"', '\'', $ctaw_content); 54 $ctaw_content = str_replace('href=\'http', 'href=\'' . $page . $symbol . 'ctaw_redirect_' . $ctaw_id . '=http', $ctaw_content); 55 56 $content = ""; 57 58 $content .= $before_widget; 59 if(!$hide_title){ 60 $content .= $before_title . $ctaw_title . $after_title; 61 } 62 $content .= $ctaw_content; 63 $content .= $after_widget; 64 65 ctaw_register_impression($ctaw_id); 66 67 return $content; 9 //Get Parent Post Cateogires 10 global $post; 11 $categories = get_the_category($post->ID); 12 //Set up category names in an array 13 foreach ($categories as $category) { 14 array_push($current_categories, $category->category_nicename); 15 } 16 17 //Get all calls to action 18 $args = array('post_type' => 'ctaw'); 19 $ctaws = get_posts($args); 20 foreach ($ctaws as $ctaw) { 21 $action_categories = array(); 22 setup_postdata($ctaw); 23 //Get call to action categories 24 $ctaw_cats = get_the_category($ctaw->ID); 25 //Set call to action category names in an array 26 foreach ($ctaw_cats as $ctaw_cat) { 27 array_push($action_categories, $ctaw_cat->category_nicename); 28 } 29 30 // either populate an array of possible actions or display an alternative action if page has no categories 31 $every_page = get_post_meta($ctaw->ID, '_is_all_ctaw', true); 32 $front_page = get_post_meta($ctaw->ID, '_is_front_ctaw', true); 33 $single_page = get_post_meta($ctaw->ID, '_is_page_ctaw', true); 34 $home_page = get_post_meta($ctaw->ID, '_is_home_ctaw', true); 35 $single_post = get_post_meta($ctaw->ID, '_is_single_ctaw', true); 36 $archive_page = get_post_meta($ctaw->ID, '_is_archive_ctaw', true); 37 $author_page = get_post_meta($ctaw->ID, '_is_author_ctaw', true); 38 $error_page = get_post_meta($ctaw->ID, '_is_404_ctaw', true); 39 $search_page = get_post_meta($ctaw->ID, '_is_search_ctaw', true); 40 41 if($every_page) 42 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 43 if($front_page && is_front_page()) 44 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 45 if($single_page && is_single()) 46 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 47 if($home_page && is_home()) 48 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 49 if($archive_page && is_archive()) 50 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 51 if($author_page && is_author()) 52 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 53 if($error_page && is_404()) 54 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 55 if($search_page && is_search()) 56 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 57 if ($single_post && count($action_categories) == 0) { 58 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 59 } else if (is_single() && $single_post && array_intersect($current_categories, $action_categories)) { 60 array_push($possible_actions, array($ctaw->ID, $ctaw->post_title, $ctaw->post_content)); 61 } 62 } 63 64 // Reset post data to keep other plugins happy 65 wp_reset_postdata(); 66 67 // Remove duplicates 68 $possible_actions = array_map("unserialize", array_unique(array_map("serialize", $possible_actions))); 69 //$alt_actions = array_map("unserialize", array_unique(array_map("serialize", $alt_actions))); 70 //display results 71 72 $rand_key = array_rand($possible_actions, 1); 73 $ctaw_id = $possible_actions[$rand_key][0]; 74 $ctaw_title = $possible_actions[$rand_key][1]; 75 $ctaw_content = $possible_actions[$rand_key][2]; 76 77 $page = get_option('siteurl'); 78 $page = get_page_link(); 79 $symbol = (preg_match('/\?/', $page)) ? '&' : '?'; 80 $ctaw_content = str_replace('"', '\'', $ctaw_content); 81 $ctaw_content = str_replace('href=\'http', 'href=\'' . $page . $symbol . 'ctaw_redirect_' . $ctaw_id . '=http', $ctaw_content); 82 83 $content = ""; 84 85 $content .= $before_widget; 86 if (!$hide_title) { 87 $content .= $before_title . $ctaw_title . $after_title; 88 } 89 $content .= $ctaw_content; 90 $content .= $after_widget; 91 92 ctaw_register_impression($ctaw_id); 93 94 return $content; 68 95 } 69 96 … … 72 99 //============================================= 73 100 class CTAW_Widget extends WP_Widget { 74 101 75 102 /** constructor */ 76 103 function CTAW_Widget() { 77 parent::WP_Widget(false, $name = 'Call To Action Widget'); 104 parent::WP_Widget(false, $name = 'Call To Action Widget'); 78 105 } 79 106 80 107 /** @see WP_Widget::widget */ 81 function widget($args, $instance) { 82 extract( $args ); 83 echo ctaw_display_action($before_widget, $after_widget, $before_title, $after_title); 108 function widget($args, $instance) { 109 extract($args); 110 $hide_title = $instance['hide_title'] ? '1' : '0'; 111 echo ctaw_display_action($before_widget, $after_widget, $before_title, $after_title, $hide_title); 84 112 } 85 113 86 114 /** @see WP_Widget::update */ 87 function update($new_instance, $old_instance) { 88 $instance = $old_instance; 115 function update($new_instance, $old_instance) { 116 $instance = $old_instance; 117 $instance['hide_title'] = $new_instance['hide_title'] ? 1 : 0; 89 118 return $instance; 90 119 } … … 92 121 /** @see WP_Widget::form */ 93 122 function form($instance) { 94 123 $default_instance = array('hide_title' => ''); 124 ?> 125 <p><input class="checkbox" type="checkbox" <?php checked($instance['hide_title'], '1'); ?> id="<?php echo $this->get_field_id('hide_title'); ?>" name="<?php echo $this->get_field_name('hide_title'); ?>" /> <label for="<?php echo $this->get_field_id('hide_title'); ?>"><?php _e('Hide Title'); ?></label></p> 126 <?php 95 127 } 96 128 97 } // class CTAW_Widget129 } 98 130 131 // class CTAW_Widget 99 132 //============================================= 100 133 // Create 'Call to Action' shortcode 101 134 //============================================= 102 135 function ctaw_create_shortcode() { 103 return ctaw_display_action('', '', '', '', true);136 return ctaw_display_action('', '', '', '', true); 104 137 } 105 138 ?> -
call-to-action/trunk/call-to-action.php
r319796 r705928 4 4 Plugin URI: http://www.jonbishop.com/downloads/wordpress-plugins/call-to-action 5 5 Description: Displays the most relavent Call to Action in your sidebar based on the content of the page 6 Version: 1. 26 Version: 1.3 7 7 Author: Jon Bishop 8 8 Author URI: http://www.jonbishop.com … … 58 58 add_filter("manage_edit-ctaw_columns", "ctaw_columns"); 59 59 60 // Meta box 61 add_action('admin_menu', 'ctaw_add_meta_box'); 62 add_action('save_post', 'ctaw_admin_process'); 63 60 64 ?> -
call-to-action/trunk/readme.txt
r319796 r705928 4 4 Tags: widget, call to action, marketing, content sidebar, promote, advertising 5 5 Requires at least: 3.0 6 Tested up to: 3. 0.17 Stable tag: 1. 26 Tested up to: 3.5.1 7 Stable tag: 1.3 8 8 9 9 Displays the most relavent Call to Action in your sidebar based on the content of the page … … 32 32 == Changelog == 33 33 34 The current version is 1.2 (2010.12.06) 34 The current version is 1.3 (2013.04.30) 35 36 = 1.3 (2013.04.30) = 37 * Added custom meta box to choose which templates to display CTA on 35 38 36 39 = 1.2 (2010.12.06) =
Note: See TracChangeset
for help on using the changeset viewer.