Advertisement
Guest User

hide post cpt

a guest
Oct 27th, 2011
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 28.03 KB | None | 0 0
  1. /**
  2.  *
  3.  * @return unknown_type
  4.  */
  5. function wphp_init() {
  6.     global $table_prefix;
  7.     if( !defined('WPHP_TABLE_NAME') )
  8.         define('WPHP_TABLE_NAME', "${table_prefix}postmeta");
  9.     if( !defined('WP_POSTS_TABLE_NAME') )
  10.         define('WP_POSTS_TABLE_NAME', "${table_prefix}posts");
  11.     if( !defined('WPHP_DEBUG') ) {
  12.         define('WPHP_DEBUG', defined('WP_DEBUG') && WP_DEBUG ? 1 : 0);
  13.     }
  14. }
  15. wphp_init();
  16.  
  17. /**
  18.  *
  19.  * @param $msg
  20.  * @return unknown_type
  21.  */
  22. function wphp_log($msg) {
  23.     if( defined('WPHP_DEBUG') && WPHP_DEBUG )
  24.        error_log("WPHP-> $msg");
  25. }
  26.  
  27. /**
  28.  *
  29.  * @return unknown_type
  30.  */
  31. function wphp_is_front_page() {
  32.     return is_front_page();
  33. }
  34.  
  35. /**
  36.  *
  37.  * @return unknown_type
  38.  */
  39. function wphp_is_feed() {
  40.     return is_feed();
  41. }
  42.  
  43. /**
  44.  *
  45.  * @return unknown_type
  46.  */
  47. function wphp_is_category() {
  48.     return !wphp_is_front_page() && !wphp_is_feed() && is_category();
  49. }
  50.  
  51. /**
  52.  *
  53.  * @return unknown_type
  54.  */
  55. function wphp_is_tag() {
  56.     return !wphp_is_front_page() && !wphp_is_feed() && is_tag();
  57. }
  58.  
  59. /**
  60.  *
  61.  * @return unknown_type
  62.  */
  63. function wphp_is_author() {
  64.     return !wphp_is_front_page() && !wphp_is_feed() && is_author();
  65. }
  66.  
  67. /**
  68.  *
  69.  * @return unknown_type
  70.  */
  71. function wphp_is_archive() {
  72.     return !wphp_is_front_page() && !wphp_is_feed() && is_date();
  73. }
  74.  
  75. /**
  76.  *
  77.  * @return unknown_type
  78.  */
  79. function wphp_is_search() {
  80.     return is_search();
  81. }
  82.  
  83. /**
  84.  *
  85.  * @param $item_type
  86.  * @return unknown_type
  87.  */
  88. function wphp_is_applicable($item_type) {
  89.     return !is_admin() && (($item_type == 'post' && !is_single()) || $item_type == 'YOUR-POST-TYPE' || $item_type == 'page') ;
  90. }
  91.  
  92.  
  93. function _wphp_http_post($var, $default = null) {
  94.     if( isset($_POST[$var]) )
  95.        return $_POST[$var];
  96.     else
  97.         return $default;
  98. }
  99.  
  100. /**
  101.  * Creates Text Domain For Translations
  102.  * @return unknown_type
  103.  */
  104. function wphp_textdomain() {
  105.     $plugin_dir = basename(dirname(__FILE__));
  106.     load_plugin_textdomain('wp-hide-post', ABSPATH."/$plugin_dir", $plugin_dir);
  107. }
  108. add_action('init', 'wphp_textdomain');
  109.  
  110. /**
  111.  *
  112.  * @param $item_type
  113.  * @param $posts
  114.  * @return unknown_type
  115.  */
  116. function wphp_exclude_low_profile_items($item_type, $posts) {
  117.     wphp_log("called: wphp_exclude_low_profile_items");
  118.     if( $item_type != 'page' )
  119.         return $posts;   // regular posts & search results are filtered in wphp_query_posts_join
  120.     else {
  121.         if( wphp_is_applicable('page') ) {
  122.             global $wpdb;
  123.             // now loop over the pages, and exclude the ones with low profile in this context
  124.             $result = array();
  125.             $page_flags = $wpdb->get_results("SELECT post_id, meta_value FROM ".WPHP_TABLE_NAME." WHERE meta_key = '_wplp_page_flags'", OBJECT_K);
  126.             if( $posts ) {
  127.                 foreach($posts as $post) {
  128.                     $check = isset($page_flags[ $post->ID ]) ? $page_flags[ $post->ID ]->meta_value : null;
  129.                     if( ($check == 'front' && wphp_is_front_page()) || $check == 'all') {
  130.                         // exclude page
  131.                     } else
  132.                         $result[] = $post;
  133.                 }
  134.             }
  135.             return $result;
  136.         } else
  137.             return $posts;
  138.     }
  139. }
  140.  
  141. /**
  142.  * Hook function to filter out hidden pages (get_pages)
  143.  * @param $posts
  144.  * @return unknown_type
  145.  */
  146. function wphp_exclude_low_profile_pages($posts) {
  147.     wphp_log("called: wphp_exclude_low_profile_pages");
  148.     return wphp_exclude_low_profile_items('page', $posts);
  149. }
  150. add_filter('get_pages', 'wphp_exclude_low_profile_pages');
  151.  
  152. /**
  153.  *
  154.  * @param $where
  155.  * @return unknown_type
  156.  */
  157. function wphp_query_posts_where($where) {
  158.     wphp_log("called: wphp_query_posts_where");
  159.     // filter posts on one of the three kinds of contexts: front, category, feed
  160.     if( wphp_is_applicable('post') && wphp_is_applicable('YOUR-POST-TYPE') && wphp_is_applicable('page') ) {
  161.         $where .= ' AND wphptbl.post_id IS NULL ';
  162.     }
  163.     //echo "\n<!-- WPHP: ".$where." -->\n";
  164.     return $where;
  165. }
  166. add_filter('posts_where_paged', 'wphp_query_posts_where');
  167.  
  168. /**
  169.  *
  170.  * @param $join
  171.  * @return unknown_type
  172.  */
  173. function wphp_query_posts_join($join) {
  174.     wphp_log("called: wphp_query_posts_join");
  175.     if( wphp_is_applicable('post') && wphp_is_applicable('YOUR-POST-TYPE') && wphp_is_applicable('page')) {
  176.         if( !$join )
  177.             $join = '';
  178.         $join .= ' LEFT JOIN '.WPHP_TABLE_NAME.' wphptbl ON '.WP_POSTS_TABLE_NAME.'.ID = wphptbl.post_id and wphptbl.meta_key like \'_wplp_%\'';
  179.  
  180.         // filter posts
  181.  
  182.     $join .= ' AND (('.WP_POSTS_TABLE_NAME.'.post_type = \'post\' ';
  183.  
  184.         if( wphp_is_front_page() )
  185.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_front\' ';
  186.         elseif( wphp_is_category())
  187.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_category\' ';
  188.         elseif( wphp_is_tag() )
  189.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_tag\' ';
  190.         elseif( wphp_is_author() )
  191.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_author\' ';
  192.         elseif( wphp_is_archive() )
  193.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_archive\' ';
  194.             elseif( wphp_is_feed())
  195.                 $join .= ' AND wphptbl.meta_key = \'_wplp_post_feed\' ';
  196.         elseif( wphp_is_search())
  197.             $join .= ' AND wphptbl.meta_key = \'_wplp_post_search\' ';
  198.         else
  199.                     $join .= ' AND wphptbl.meta_key not like  \'_wplp_%\' ';
  200.  
  201.         $join .= ')';
  202.  
  203.         // filter YOUR-POST-TYPE
  204.  
  205.     $join .= ' OR ('.WP_POSTS_TABLE_NAME.'.post_type = \'YOUR-POST-TYPE\' ';
  206.  
  207.         if( wphp_is_front_page() )
  208.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_front\' ';
  209.         elseif( wphp_is_category())
  210.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_category\' ';
  211.         elseif( wphp_is_tag() )
  212.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_tag\' ';
  213.         elseif( wphp_is_author() )
  214.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_author\' ';
  215.         elseif( wphp_is_archive() )
  216.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_archive\' ';
  217.             elseif( wphp_is_feed())
  218.                 $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_feed\' ';
  219.         elseif( wphp_is_search())
  220.             $join .= ' AND wphptbl.meta_key = \'_wplp_YOUR-POST-TYPE_search\' ';
  221.         else
  222.                     $join .= ' AND wphptbl.meta_key not like  \'_wplp_%\' ';
  223.  
  224.         $join .= ')';
  225.  
  226.         // pages
  227.  
  228.         $join .= ' OR ('.WP_POSTS_TABLE_NAME.'.post_type = \'page\' AND wphptbl.meta_key <> \'_wplp_page_flags\'';
  229.  
  230.             if( wphp_is_search())
  231.                     $join .= ' AND wphptbl.meta_key = \'_wplp_page_search\' ';
  232.             else
  233.                     $join .= ' AND wphptbl.meta_key not like \'_wplp_%\' ';
  234.             $join .= '))';  
  235.     }
  236.     //echo "\n<!-- WPHP: ".$join." -->\n";
  237.     return $join;
  238. }
  239. add_filter('posts_join_paged', 'wphp_query_posts_join');
  240.  
  241.  
  242. /*********************
  243.  * ADMIN FUNCTIONS
  244.  *********************/
  245.  
  246.  
  247. /**
  248.  * Hook called when activating the plugin
  249.  * @return unknown_type
  250.  */
  251. function wphp_activate() {
  252.     wphp_init();
  253.     wphp_log("called: wphp_activate");
  254.    
  255.     require_once(dirname(__FILE__).'/upgrade.php');
  256.     wphp_migrate_db();
  257.     wphp_remove_wp_low_profiler();
  258. }
  259. add_action('activate_wp-hide-post/wp-hide-post.php', 'wphp_activate' );
  260. //register_activation_hook( __FILE__, 'wphp_activate' );
  261.  
  262.  
  263. /**
  264.  * Hook to watch for the activation of 'WP low Profiler', and forbid it...
  265.  * @return unknown_type
  266.  */
  267. function wphp_activate_lowprofiler() {
  268.     wphp_log("called: wphp_activate_lowprofiler");
  269.     require_once(dirname(__FILE__).'/upgrade.php');
  270.     wphp_migrate_db();  // in case any tables were created, clean them up
  271.     wphp_remove_wp_low_profiler();  // remove the files of the plugin
  272.  
  273.     $msgbox = __("'WP low Profiler' has been deprecated and replaced by 'WP Hide Post' which you already have active! Activation failed and plugin files cleaned up.", 'wp-hide-post');
  274.     $err1_sorry = __("Cannot install 'WP low Profiler' because of a conflict. Sorry for this inconvenience.", 'wp-hide-post');
  275.     $err2_cleanup = __("The downloaded files were cleaned-up and no further action is required.", 'wp-hide-post');
  276.     $err3_return = __("Return to plugins page...", 'wp-hide-post');
  277.     $return_url = admin_url('plugins.php');
  278.    
  279.     $html = <<<HTML
  280. ${err1_sorry}<br />${err2_cleanup}<br /><a href="${$return_url}">${err3_return}</a>
  281. <script language="javascript">window.alert("${msgbox}");</script>
  282. HTML;
  283.     // show the error page with the message...  
  284.     wp_die($html, 'WP low Profiler Activation Not Allowed', array( 'response' => '200') );
  285. }
  286. add_action('activate_wp-low-profiler/wp-low-profiler.php', 'wphp_activate_lowprofiler' );
  287.  
  288. /**
  289.  * @param $action_links
  290.  * @param $plugin
  291.  * @return unknown_type
  292.  */
  293. function plugin_install_action_links_wp_lowprofiler($action_links, $plugin) {
  294.     wphp_log("called: plugin_install_action_links_wp_lowprofiler");
  295.     if( $plugin['name'] == 'WP low Profiler' ) {
  296.         $alt = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&amp;plugin=wp-hide-post&amp;TB_iframe=true&amp;width=600&amp;height=800') . '" class="thickbox onclick" title="WP Hide Post">' . __('Check "WP Hide Post"') . '</a>';
  297.         $action_links = array(
  298.             __('Deprecated'),
  299.             $alt);
  300.     }
  301.     return $action_links;
  302. }
  303. add_filter('plugin_install_action_links', 'plugin_install_action_links_wp_lowprofiler', 10, 2);
  304.  
  305. /**
  306.  *
  307.  * @param $id
  308.  * @param $lp_flag
  309.  * @param $lp_value
  310.  * @return unknown_type
  311.  */
  312. function wphp_update_visibility($id, $lp_flag, $lp_value) {
  313.     wphp_log("called: wphp_update_visibility");
  314.     global $wpdb;
  315.     $item_type = get_post_type($id);
  316.     if( ($item_type == 'post' && !$lp_value) || ($item_type == 'YOUR-POST-TYPE' && !$lp_value) || ($item_type == 'page' && ( ($lp_flag == '_wplp_page_flags' && $lp_value == 'none') || ($lp_flag == '_wplp_page_search' && !$lp_value) ) ) ) {
  317.         wphp_unset_low_profile($item_type, $id, $lp_flag);
  318.     } else {
  319.         wphp_set_low_profile($item_type, $id, $lp_flag, $lp_value);
  320.     }
  321. }
  322.  
  323. /**
  324.  *
  325.  * @param $item_type
  326.  * @param $id
  327.  * @param $lp_flag
  328.  * @return unknown_type
  329.  */
  330. function wphp_unset_low_profile($item_type, $id, $lp_flag) {
  331.     wphp_log("called: wphp_unset_low_profile");
  332.     global $wpdb;
  333.     // Delete the flag from the database table
  334.     $wpdb->query("DELETE FROM ".WPHP_TABLE_NAME." WHERE post_id = $id AND meta_key = '$lp_flag'");
  335. }
  336.  
  337. /**
  338.  *
  339.  * @param $item_type
  340.  * @param $id
  341.  * @param $lp_flag
  342.  * @param $lp_value
  343.  * @return unknown_type
  344.  */
  345. function wphp_set_low_profile($item_type, $id, $lp_flag, $lp_value) {
  346.     wphp_log("called: wphp_set_low_profile");
  347.     global $wpdb;  
  348.     // Ensure No Duplicates!
  349.     $check = $wpdb->get_var("SELECT count(*) FROM ".WPHP_TABLE_NAME." WHERE post_id = $id AND meta_key='$lp_flag'");
  350.     if(!$check) {
  351.         $wpdb->query("INSERT INTO ".WPHP_TABLE_NAME."(post_id, meta_key, meta_value) VALUES($id, '$lp_flag', '$lp_value')");
  352.     } elseif( $item_type == 'page' && $lp_flag == "_wplp_page_flags" ) {
  353.         $wpdb->query("UPDATE ".WPHP_TABLE_NAME." set meta_value = '$lp_value' WHERE post_id = $id and meta_key = '$lp_flag'");
  354.     }
  355. }
  356.  
  357. /**
  358.  *
  359.  * @return unknown_type
  360.  */
  361. function wphp_add_post_edit_meta_box() {
  362.     wphp_log("called: wphp_add_post_edit_meta_box");
  363.     global $wp_version;
  364.     if( ! $wp_version || $wp_version >= '2.7' ) {
  365.         add_meta_box('hidepostdivpost', __('Post Visibility', 'wp-hide-post'), 'wphp_metabox_post_edit', 'post', 'side');
  366.         add_meta_box('hidepostdivYOUR-POST-TYPE', __('YOUR-POST-TYPE Visibility', 'wp-hide-post'), 'wphp_metabox_YOUR-POST-TYPE_edit', 'YOUR-POST-TYPE', 'side');
  367.         add_meta_box('hidepostdivpage', __('Page Visibility', 'wp-hide-post'), 'wphp_metabox_page_edit', 'page', 'side');
  368.     } else {
  369.         add_meta_box('hidepostdivpost', __('Post Visibility', 'wp-hide-post'), 'wphp_metabox_post_edit', 'post');
  370.         add_meta_box('hidepostdivpost', __('YOUR-POST-TYPE Visibility', 'wp-hide-post'), 'wphp_metabox_YOUR-POST-TYPE_edit', 'YOUR-POST-TYPE');
  371.         add_meta_box('hidepostdivpage', __('Page Visibility', 'wp-hide-post'), 'wphp_metabox_page_edit', 'page');
  372.     }
  373.    
  374. }
  375. add_action('admin_menu', 'wphp_add_post_edit_meta_box');
  376.  
  377. /**
  378.  *
  379.  * @return unknown_type
  380.  */
  381. function wphp_metabox_post_edit() {
  382.     wphp_log("called: wphp_metabox_post_edit");
  383.     global $wpdb;
  384.    
  385.     $id = isset($_GET['post']) ? intval($_GET['post']) : 0;
  386.  
  387.     $wplp_post_front = 0;
  388.     $wplp_post_category = 0;
  389.     $wplp_post_tag = 0;
  390.     $wplp_post_author = 0;
  391.     $wplp_post_archive = 0;
  392.     $wplp_post_search = 0;
  393.     $wplp_post_feed = 0;
  394.    
  395.     if($id > 0) {
  396.         $flags = $wpdb->get_results("SELECT meta_key from ".WPHP_TABLE_NAME." where post_id = $id and meta_key like '_wplp_%'", ARRAY_N);
  397.         if( $flags ) {
  398.             foreach($flags as $flag_array) {
  399.                 $flag = $flag_array[0];
  400.                 // remove the leading _
  401.                 $flag = substr($flag, 1, strlen($flag)-1);
  402.                 ${$flag} = 1;
  403.             }
  404.         }
  405.     }
  406. ?>
  407.     <label for="wplp_post_front" class="selectit"><input type="checkbox" id="wplp_post_front" name="wplp_post_front" value="1"<?php checked($wplp_post_front, 1); ?>/>&nbsp;<?php _e('Hide on the front page.', 'wp-hide-post'); ?></label>
  408.     <input type="hidden" name="old_wplp_post_front" value="<?php echo $wplp_post_front; ?>"/>
  409.     <br />
  410.     <label for="wplp_post_category" class="selectit"><input type="checkbox" id="wplp_post_category" name="wplp_post_category" value="1"<?php checked($wplp_post_category, 1); ?>/>&nbsp;<?php _e('Hide on category pages.', 'wp-hide-post'); ?></label>
  411.     <input type="hidden" name="old_wplp_post_category" value="<?php echo $wplp_post_category; ?>"/>
  412.     <br />
  413.     <label for="wplp_post_tag" class="selectit"><input type="checkbox" id="wplp_post_tag" name="wplp_post_tag" value="1"<?php checked($wplp_post_tag, 1); ?>/>&nbsp;<?php _e('Hide on tag pages.', 'wp-hide-post'); ?></label>
  414.     <input type="hidden" name="old_wplp_post_tag" value="<?php echo $wplp_post_tag; ?>"/>
  415.     <br />
  416.     <label for="wplp_post_author" class="selectit"><input type="checkbox" id="wplp_post_author" name="wplp_post_author" value="1"<?php checked($wplp_post_author, 1); ?>/>&nbsp;<?php _e('Hide on author pages.', 'wp-hide-post'); ?></label>
  417.     <input type="hidden" name="old_wplp_post_author" value="<?php echo $wplp_post_author; ?>"/>
  418.     <br />
  419.     <label for="wplp_post_archive" class="selectit"><input type="checkbox" id="wplp_post_archive" name="wplp_post_archive" value="1"<?php checked($wplp_post_archive, 1); ?>/>&nbsp;<?php _e('Hide in date archives (month, day, year, etc...)', 'wp-hide-post'); ?></label>
  420.     <input type="hidden" name="old_wplp_post_archive" value="<?php echo $wplp_post_archive; ?>"/>
  421.     <br />
  422.     <label for="wplp_post_search" class="selectit"><input type="checkbox" id="wplp_post_search" name="wplp_post_search" value="1"<?php checked($wplp_post_search, 1); ?>/>&nbsp;<?php _e('Hide in search results.', 'wp-hide-post'); ?></label>
  423.     <input type="hidden" name="old_wplp_post_search" value="<?php echo $wplp_post_search; ?>"/>
  424.     <br />
  425.     <label for="wplp_post_feed" class="selectit"><input type="checkbox" id="wplp_post_feed" name="wplp_post_feed" value="1"<?php checked($wplp_post_feed, 1); ?>/>&nbsp;<?php _e('Hide in feeds.', 'wp-hide-post'); ?></label>
  426.     <input type="hidden" name="old_wplp_post_feed" value="<?php echo $wplp_post_feed; ?>"/>
  427.     <br />
  428.     <div style="float:right;font-size: xx-small;"><a href="http://anappleaday.konceptus.net/posts/wp-hide-post/#comments"><?php _e("Leave feedback and report bugs...", 'wp-hide-post'); ?></a></div>
  429.     <br />
  430.     <div style="float:right;font-size: xx-small;"><a href="http://wordpress.org/extend/plugins/wp-hide-post/"><?php _e("Give 'WP Hide Post' a good rating...", 'wp-hide-post'); ?></a></div>
  431.     <br />
  432. <?php
  433. }
  434.  
  435. /**
  436.  *
  437.  * @return unknown_type
  438.  */
  439. function wphp_metabox_YOUR-POST-TYPE_edit() {
  440.     wphp_log("called: wphp_metabox_YOUR-POST-TYPE_edit");
  441.     global $wpdb;
  442.    
  443.     $id = isset($_GET['post']) ? intval($_GET['post']) : 0;
  444.  
  445.     $wplp_YOUR-POST-TYPE_front = 0;
  446.     $wplp_YOUR-POST-TYPE_category = 0;
  447.     $wplp_YOUR-POST-TYPE_tag = 0;
  448.     $wplp_YOUR-POST-TYPE_author = 0;
  449.     $wplp_YOUR-POST-TYPE_archive = 0;
  450.     $wplp_YOUR-POST-TYPE_search = 0;
  451.     $wplp_YOUR-POST-TYPE_feed = 0;
  452.    
  453.     if($id > 0) {
  454.         $flags = $wpdb->get_results("SELECT meta_key from ".WPHP_TABLE_NAME." where post_id = $id and meta_key like '_wplp_%'", ARRAY_N);
  455.         if( $flags ) {
  456.             foreach($flags as $flag_array) {
  457.                 $flag = $flag_array[0];
  458.                 // remove the leading _
  459.                 $flag = substr($flag, 1, strlen($flag)-1);
  460.                 ${$flag} = 1;
  461.             }
  462.         }
  463.     }
  464. ?>
  465.     <label for="wplp_YOUR-POST-TYPE_front" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_front" name="wplp_YOUR-POST-TYPE_front" value="1"<?php checked($wplp_YOUR-POST-TYPE_front, 1); ?>/>&nbsp;<?php _e('Hide on the front page.', 'wp-hide-post'); ?></label>
  466.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_front" value="<?php echo $wplp_YOUR-POST-TYPE_front; ?>"/>
  467.     <br />
  468.     <label for="wplp_YOUR-POST-TYPE_category" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_category" name="wplp_YOUR-POST-TYPE_category" value="1"<?php checked($wplp_YOUR-POST-TYPE_category, 1); ?>/>&nbsp;<?php _e('Hide on category pages.', 'wp-hide-post'); ?></label>
  469.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_category" value="<?php echo $wplp_YOUR-POST-TYPE_category; ?>"/>
  470.     <br />
  471.     <label for="wplp_YOUR-POST-TYPE_tag" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_tag" name="wplp_YOUR-POST-TYPE_tag" value="1"<?php checked($wplp_YOUR-POST-TYPE_tag, 1); ?>/>&nbsp;<?php _e('Hide on tag pages.', 'wp-hide-post'); ?></label>
  472.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_tag" value="<?php echo $wplp_YOUR-POST-TYPE_tag; ?>"/>
  473.     <br />
  474.     <label for="wplp_YOUR-POST-TYPE_author" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_author" name="wplp_YOUR-POST-TYPE_author" value="1"<?php checked($wplp_YOUR-POST-TYPE_author, 1); ?>/>&nbsp;<?php _e('Hide on author pages.', 'wp-hide-post'); ?></label>
  475.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_author" value="<?php echo $wplp_YOUR-POST-TYPE_author; ?>"/>
  476.     <br />
  477.     <label for="wplp_YOUR-POST-TYPE_archive" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_archive" name="wplp_YOUR-POST-TYPE_archive" value="1"<?php checked($wplp_YOUR-POST-TYPE_archive, 1); ?>/>&nbsp;<?php _e('Hide in date archives (month, day, year, etc...)', 'wp-hide-post'); ?></label>
  478.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_archive" value="<?php echo $wplp_YOUR-POST-TYPE_archive; ?>"/>
  479.     <br />
  480.     <label for="wplp_YOUR-POST-TYPE_search" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_search" name="wplp_YOUR-POST-TYPE_search" value="1"<?php checked($wplp_YOUR-POST-TYPE_search, 1); ?>/>&nbsp;<?php _e('Hide in search results.', 'wp-hide-post'); ?></label>
  481.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_search" value="<?php echo $wplp_YOUR-POST-TYPE_search; ?>"/>
  482.     <br />
  483.     <label for="wplp_YOUR-POST-TYPE_feed" class="selectit"><input type="checkbox" id="wplp_YOUR-POST-TYPE_feed" name="wplp_YOUR-POST-TYPE_feed" value="1"<?php checked($wplp_YOUR-POST-TYPE_feed, 1); ?>/>&nbsp;<?php _e('Hide in feeds.', 'wp-hide-post'); ?></label>
  484.     <input type="hidden" name="old_wplp_YOUR-POST-TYPE_feed" value="<?php echo $wplp_YOUR-POST-TYPE_feed; ?>"/>
  485.     <br />
  486.     <div style="float:right;font-size: xx-small;"><a href="http://anappleaday.konceptus.net/posts/wp-hide-post/#comments"><?php _e("Leave feedback and report bugs...", 'wp-hide-post'); ?></a></div>
  487.     <br />
  488.     <div style="float:right;font-size: xx-small;"><a href="http://wordpress.org/extend/plugins/wp-hide-post/"><?php _e("Give 'WP Hide Post' a good rating...", 'wp-hide-post'); ?></a></div>
  489.     <br />
  490. <?php
  491. }
  492.  
  493. /**
  494.  *
  495.  * @return unknown_type
  496.  */
  497. function wphp_metabox_page_edit() {
  498.     wphp_log("called: wphp_metabox_page_edit");
  499.     global $wpdb;
  500.    
  501.     $id = isset($_GET['post']) ? intval($_GET['post']) : 0;
  502.  
  503.     $wplp_page = 'none';
  504.     $wplp_page_search_show = 1;
  505.    
  506.     if($id > 0) {
  507.         $flags = $wpdb->get_results("SELECT meta_value from ".WPHP_TABLE_NAME." where post_id = $id and meta_key = '_wplp_page_flags'", ARRAY_N);
  508.         if( $flags )
  509.             $wplp_page = $flags[0][0];
  510.         $search = $wpdb->get_results("SELECT meta_value from ".WPHP_TABLE_NAME." where post_id = $id and meta_key = '_wplp_page_search'", ARRAY_N);
  511.         if( $search )
  512.             $wplp_page_search_show = ! $search[0][0];
  513.     }
  514. ?>
  515.     <input type="hidden" name="old_wplp_page" value="<?php echo $wplp_page; ?>"/>
  516.     <label class="selectit"><input type="radio" id="wplp_page_none" name="wplp_page" value="none"<?php checked($wplp_page, 'none'); ?>/>&nbsp;<?php _e('Show normally everywhere.', 'wp-hide-post'); ?></label>
  517.     <br />
  518.     <br />
  519.     <label class="selectit"><input type="radio" id="wplp_page_front" name="wplp_page" value="front"<?php checked($wplp_page, 'front'); ?>/>&nbsp;<?php _e('Hide when listing pages on the front page.', 'wp-hide-post'); ?></label>
  520.     <br />
  521.     <br />
  522.     <label class="selectit"><input type="radio" id="wplp_page_all" name="wplp_page" value="all"<?php checked($wplp_page, 'all'); ?>/>&nbsp;<?php _e('Hide everywhere pages are listed.', 'wp-hide-post'); ?><sup>*</sup></label>
  523.     <div style="height:18px;margin-left:20px">
  524.         <div id="wplp_page_search_show_div">
  525.             <label class="selectit"><input type="checkbox" id="wplp_page_search_show" name="wplp_page_search_show" value="1"<?php checked($wplp_page_search_show, 1); ?>/>&nbsp;<?php _e('Keep in search results.', 'wp-hide-post'); ?></label>
  526.             <input type="hidden" name="old_wplp_page_search_show" value="<?php echo $wplp_page_search_show; ?>"/>
  527.         </div>
  528.     </div>
  529.     <br />
  530.     <div style="float:right;clear:both;font-size:x-small;">* Will still show up in sitemap.xml if you generate one automatically. See <a href="http://anappleaday.konceptus.net/posts/wp-low-profiler/">details</a>.</div>
  531.     <br />
  532.     <br />
  533.     <br />
  534.     <div style="float:right;font-size: xx-small;"><a href="http://anappleaday.konceptus.net/posts/wp-hide-post/#comments"><?php _e("Leave feedback and report bugs...", 'wp-hide-post'); ?></a></div>
  535.     <br />
  536.     <div style="float:right;clear:both;font-size:xx-small;"><a href="http://wordpress.org/extend/plugins/wp-hide-post/"><?php _e("Give 'WP Hide Post' a good rating...", 'wp-hide-post'); ?></a></div>
  537.     <br />
  538.     <script type="text/javascript">
  539.     <!--
  540.         // toggle the wplp_page_search_show checkbox
  541.         var wplp_page_search_show_callback = function () {
  542.             if(jQuery("#wplp_page_all").is(":checked"))
  543.                 jQuery("#wplp_page_search_show_div").show();
  544.             else
  545.                 jQuery("#wplp_page_search_show_div").hide();
  546.         };
  547.         jQuery("#wplp_page_all").change(wplp_page_search_show_callback);
  548.         jQuery("#wplp_page_front").change(wplp_page_search_show_callback);
  549.         jQuery("#wplp_page_none").change(wplp_page_search_show_callback);
  550.         jQuery(document).ready( wplp_page_search_show_callback );
  551.     //-->
  552.     </script>
  553. <?php
  554. }
  555.  
  556. /**
  557.  *
  558.  * @param $id
  559.  * @return unknown_type
  560.  */
  561. function wphp_save_post($id) {
  562.     wphp_log("called: wphp_save_post");
  563.     $item_type = get_post_type($id);
  564.     if( $item_type == 'post' ) {
  565.         if( isset($_POST['old_wplp_post_front']) && _wphp_http_post('wplp_post_front', 0) != _wphp_http_post('old_wplp_post_front', 0) )
  566.           wphp_update_visibility($id, '_wplp_post_front', _wphp_http_post('wplp_post_front', 0));
  567.         if( isset($_POST['old_wplp_post_category']) && _wphp_http_post('wplp_post_category', 0) != _wphp_http_post('old_wplp_post_category', 0) )
  568.           wphp_update_visibility($id, '_wplp_post_category', _wphp_http_post('wplp_post_category', 0));
  569.         if( isset($_POST['old_wplp_post_tag']) && _wphp_http_post('wplp_post_tag', 0) != _wphp_http_post('old_wplp_post_tag', 0) )
  570.           wphp_update_visibility($id, '_wplp_post_tag', _wphp_http_post('wplp_post_tag', 0));
  571.         if( isset($_POST['old_wplp_post_author']) && _wphp_http_post('wplp_post_author', 0) != _wphp_http_post('old_wplp_post_author', 0) )
  572.           wphp_update_visibility($id, '_wplp_post_author', _wphp_http_post('wplp_post_author', 0));
  573.         if( isset($_POST['old_wplp_post_archive']) && _wphp_http_post('wplp_post_archive', 0) != _wphp_http_post('old_wplp_post_archive', 0) )
  574.           wphp_update_visibility($id, '_wplp_post_archive', _wphp_http_post('wplp_post_archive', 0));
  575.         if( isset($_POST['old_wplp_post_search']) && _wphp_http_post('wplp_post_search', 0) != _wphp_http_post('old_wplp_post_search', 0) )
  576.           wphp_update_visibility($id, '_wplp_post_search', _wphp_http_post('wplp_post_search', 0));
  577.         if( isset($_POST['old_wplp_post_feed']) && _wphp_http_post('wplp_post_feed', 0) != _wphp_http_post('old_wplp_post_feed', 0) )
  578.           wphp_update_visibility($id, '_wplp_post_feed', _wphp_http_post('wplp_post_feed', 0));
  579.     } elseif ( $item_type == 'YOUR-POST-TYPE' ) {
  580.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_front']) && _wphp_http_post('wplp_YOUR-POST-TYPE_front', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_front', 0) )
  581.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_front', _wphp_http_post('wplp_YOUR-POST-TYPE_front', 0));
  582.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_category']) && _wphp_http_post('wplp_YOUR-POST-TYPE_category', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_category', 0) )
  583.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_category', _wphp_http_post('wplp_YOUR-POST-TYPE_category', 0));
  584.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_tag']) && _wphp_http_post('wplp_YOUR-POST-TYPE_tag', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_tag', 0) )
  585.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_tag', _wphp_http_post('wplp_YOUR-POST-TYPE_tag', 0));
  586.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_author']) && _wphp_http_post('wplp_YOUR-POST-TYPE_author', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_author', 0) )
  587.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_author', _wphp_http_post('wplp_YOUR-POST-TYPE_author', 0));
  588.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_archive']) && _wphp_http_post('wplp_YOUR-POST-TYPE_archive', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_archive', 0) )
  589.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_archive', _wphp_http_post('wplp_YOUR-POST-TYPE_archive', 0));
  590.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_search']) && _wphp_http_post('wplp_YOUR-POST-TYPE_search', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_search', 0) )
  591.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_search', _wphp_http_post('wplp_YOUR-POST-TYPE_search', 0));
  592.         if( isset($_POST['old_wplp_YOUR-POST-TYPE_feed']) && _wphp_http_post('wplp_YOUR-POST-TYPE_feed', 0) != _wphp_http_post('old_wplp_YOUR-POST-TYPE_feed', 0) )
  593.           wphp_update_visibility($id, '_wplp_YOUR-POST-TYPE_feed', _wphp_http_post('wplp_YOUR-POST-TYPE_feed', 0));
  594.     } elseif( $item_type == 'page' ) {
  595.         if( isset($_POST['old_wplp_page']) ) {
  596.             if( _wphp_http_post('wplp_page', 'none') != _wphp_http_post('old_wplp_page', 'none') ) {
  597.                 wphp_update_visibility($id, "_wplp_page_flags", _wphp_http_post('wplp_page', 'none'));
  598.             }
  599.             if( _wphp_http_post('wplp_page', 'none') == 'all' ) {
  600.                 if( isset($_POST['old_wplp_page_search_show']) && _wphp_http_post('wplp_page_search_show', 0) != _wphp_http_post('old_wplp_page_search_show', 0) )
  601.                     wphp_update_visibility($id, "_wplp_page_search", ! _wphp_http_post('wplp_page_search_show', 0));
  602.             } else
  603.                 wphp_update_visibility($id, "_wplp_page_search", 0);
  604.         }
  605.     }  
  606. }
  607. add_action('save_post', 'wphp_save_post');
  608.  
  609. /**
  610.  *
  611.  * @param $post_id
  612.  * @return unknown_type
  613.  */
  614. function wphp_delete_post($post_id) {
  615.     wphp_log("called: wphp_delete_post");
  616.     global $wpdb;
  617.     // Delete all post flags from the database table
  618.     $wpdb->query("DELETE FROM ".WPHP_TABLE_NAME." WHERE post_id = $post_id and meta_key like '_wplp_%'");
  619. }
  620. add_action('delete_post', 'wphp_delete_post');
  621.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement