|
1 <?php |
|
2 /* |
|
3 Plugin Name: Twitter Tools - Exclude Category |
|
4 Plugin URI: http://crowdfavorite.com/wordpress/ |
|
5 Description: Exclude posts in certain categories from being tweeted by Twitter Tools. This plugin relies on Twitter Tools, configure it on the Twitter Tools settings page. |
|
6 Version: 2.0 |
|
7 Author: Crowd Favorite |
|
8 Author URI: http://crowdfavorite.com |
|
9 */ |
|
10 |
|
11 // ini_set('display_errors', '1'); ini_set('error_reporting', E_ALL); |
|
12 |
|
13 if (!defined('PLUGINDIR')) { |
|
14 define('PLUGINDIR','wp-content/plugins'); |
|
15 } |
|
16 |
|
17 load_plugin_textdomain('twitter-tools-excludecat'); |
|
18 |
|
19 function aktt_excludecat_request_handler() { |
|
20 if (!empty($_POST['cf_action'])) { |
|
21 switch ($_POST['cf_action']) { |
|
22 case 'aktt_excludecat_update_settings': |
|
23 aktt_excludecat_save_settings(); |
|
24 wp_redirect(trailingslashit(get_bloginfo('wpurl')).'wp-admin/options-general.php?page=twitter-tools.php&updated=true'); |
|
25 die(); |
|
26 break; |
|
27 } |
|
28 } |
|
29 } |
|
30 add_action('init', 'aktt_excludecat_request_handler'); |
|
31 |
|
32 function aktt_excludecat_do_blog_post_tweet($tweet, $post) { |
|
33 $cats = get_option('aktt_excludecats'); |
|
34 if (is_array($cats) && count($cats)) { |
|
35 foreach ($cats as $cat) { |
|
36 if (in_category($cat, $post)) { |
|
37 return false; |
|
38 } |
|
39 } |
|
40 } |
|
41 return $tweet; |
|
42 } |
|
43 add_filter('aktt_do_blog_post_tweet', 'aktt_excludecat_do_blog_post_tweet', 10, 2); |
|
44 |
|
45 function aktt_excludecat_settings_form() { |
|
46 print(' |
|
47 <style class="text/css"> |
|
48 #aktt_exclude_cat_options { |
|
49 list-style: none; |
|
50 } |
|
51 #aktt_exclude_cat_options li { |
|
52 float: left; |
|
53 margin: 0 0 5px 0; |
|
54 padding: 3px; |
|
55 width: 200px; |
|
56 } |
|
57 </style> |
|
58 <script type="text/javascript"> |
|
59 jQuery(function() { |
|
60 jQuery("#aktt_excludecat_select").click(function() { |
|
61 jQuery("#aktt_exclude_cat_options input[type=checkbox]").attr("checked", true); |
|
62 return false; |
|
63 }); |
|
64 jQuery("#aktt_excludecat_unselect").click(function() { |
|
65 jQuery("#aktt_exclude_cat_options input[type=checkbox]").attr("checked", false); |
|
66 return false; |
|
67 }); |
|
68 }); |
|
69 </script> |
|
70 <div class="wrap"> |
|
71 <h2>'.__('Exclude Categories for Twitter Tools', 'twitter-tools-excludecat').'</h2> |
|
72 <form id="aktt_excludecat_settings_form" name="aktt_excludecat_settings_form" action="'.get_bloginfo('wpurl').'/wp-admin/options-general.php" method="post"> |
|
73 <input type="hidden" name="cf_action" value="aktt_excludecat_update_settings" /> |
|
74 <fieldset class="options"> |
|
75 <p>'.__('Posts in selected categories will be excluded from blog post tweets', 'twitter-tools-excludecat').'</p> |
|
76 <p><a href="#" id="aktt_excludecat_select">'.__('Select All', 'twitter-tools-excludecat').'</a> | <a href="#" id="aktt_excludecat_unselect">'.__('Unselect All', 'twitter-tools-excludecat').'</a></p> |
|
77 <ul id="aktt_exclude_cat_options"> |
|
78 '); |
|
79 |
|
80 $categories = get_categories('hide_empty=0'); |
|
81 $exclude_cats = get_option('aktt_excludecats'); |
|
82 if (!is_array($exclude_cats)) { |
|
83 $exclude_cats = array(); |
|
84 } |
|
85 foreach ($categories as $cat) { |
|
86 $id = 'aktt_exclude_cat_'.$cat->term_id; |
|
87 in_array($cat->term_id, $exclude_cats) ? $checked = ' checked="checked"' : $checked = ''; |
|
88 print(' |
|
89 <li> |
|
90 <input type="checkbox" name="aktt_exclude_cats[]" value="'.$cat->term_id.'" id="'.$id.'" '.$checked.' /> |
|
91 <label for="'.$id.'">'.htmlspecialchars($cat->name).'</label> |
|
92 </li> |
|
93 '); |
|
94 } |
|
95 print(' |
|
96 </ul> |
|
97 <div class="clear"></div> |
|
98 </fieldset> |
|
99 <p class="submit"> |
|
100 <input type="submit" name="submit" value="'.__('Save Settings', 'twitter-tools-excludecat').'" class="button-primary" /> |
|
101 </p> |
|
102 </form> |
|
103 </div> |
|
104 '); |
|
105 } |
|
106 add_action('aktt_options_form', 'aktt_excludecat_settings_form'); |
|
107 |
|
108 function aktt_excludecat_save_settings() { |
|
109 if (!current_user_can('manage_options')) { |
|
110 return; |
|
111 } |
|
112 $cats = array(); |
|
113 if (isset($_POST['aktt_exclude_cats']) && is_array($_POST['aktt_exclude_cats'])) { |
|
114 foreach ($_POST['aktt_exclude_cats'] as $cat_id) { |
|
115 $cat_id = intval($cat_id); |
|
116 if ($cat_id) { |
|
117 $cats[] = $cat_id; |
|
118 } |
|
119 } |
|
120 } |
|
121 update_option('aktt_excludecats', $cats); |
|
122 } |
|
123 |
|
124 //a:21:{s:11:"plugin_name";s:34:"Twitter Tools - Exclude Categories";s:10:"plugin_uri";s:35:"http://crowdfavorite.com/wordpress/";s:18:"plugin_description";s:72:"Exclude posts in certain categories from being tweeted by Twitter Tools.";s:14:"plugin_version";s:3:"1.0";s:6:"prefix";s:15:"aktt_excludecat";s:12:"localization";s:24:"twitter-tools-excludecat";s:14:"settings_title";s:34:"Exclude Category for Twitter Tools";s:13:"settings_link";s:34:"Exclude Category for Twitter Tools";s:4:"init";b:0;s:7:"install";b:0;s:9:"post_edit";b:0;s:12:"comment_edit";b:0;s:6:"jquery";b:0;s:6:"wp_css";b:0;s:5:"wp_js";b:0;s:9:"admin_css";b:0;s:8:"admin_js";b:0;s:15:"request_handler";s:1:"1";s:6:"snoopy";b:0;s:11:"setting_cat";s:1:"1";s:14:"setting_author";b:0;} |
|
125 |
|
126 ?> |