Changeset 1098621
- Timestamp:
- 02/24/2015 11:29:23 PM (11 years ago)
- Location:
- disable-delete-post-or-page-link-wordpress-plugin
- Files:
-
- 3 added
- 2 edited
-
tags/1.0 (added)
-
tags/1.0/js_disable_delete_post.php (added)
-
tags/1.0/readme.txt (added)
-
trunk/js_disable_delete_post.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
disable-delete-post-or-page-link-wordpress-plugin/trunk/js_disable_delete_post.php
r553569 r1098621 1 <?php 2 /* 3 * Plugin Name: Disable Delete Post or Page 4 * Plugin URI: http://reactivedevelopment.net/disable-delete-post-page 5 * Description: Allows the administrator to remove the delete post link from a post or page. 6 * Version: 1.0 7 * Author: Reactive Development LLC 8 * Author URI: http://www.reactivedevelopment.net/ 1 <?php /** 2 3 Plugin Name: Disable Delete Post or Page 4 Plugin URI: http://reactivedevelopment.net/disable-delete-post-page 5 Description: Allows the administrator to remove the delete post link from a post or page. 6 Version: 2.0 7 9 8 * 10 * License: GNU General Public License, v2 (or newer) 11 * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 9 10 Author: Jeremy Selph, Reactive Development LLC 11 Author URI: http://www.reactivedevelopment.net/ 12 13 License: GNU General Public License, v3 (or newer) 14 License URI: http://www.gnu.org/licenses/gpl-3.0.html 15 12 16 * 13 17 * This program is free software; you can redistribute it and/or modify 14 18 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2of the License, or19 * the Free Software Foundation; either version 3 of the License, or 16 20 * (at your option) any later version. 17 21 * … … 21 25 * GNU General Public License for more details. 22 26 * 23 * This program was modified from MaxBlogPress Favicon plugin, version 2.2.5, 24 * Copyright (C) 2007 www.maxblogpress.com, released under the GNU General Public License. 25 */ 26 27 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 28 /// when we activate the plugin do this 29 30 function install_js_disable_delete_post() { 31 $currentJSDeletePostOption = unserialize( get_option( "jsDisableDeletePost", "" ) ); 32 if ( empty( $currentJSDeletePostOption ) ){ 33 add_option( "jsDisableDeletePost", "yes", "", "yes" ); } 34 } register_activation_hook(__FILE__,'install_js_disable_delete_post'); 35 36 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 37 /// remove the delete link from the page/posts list 38 39 function js_remove_delete_link_from_post_list( $actions, $post ){ 40 41 // get this posts jsRemoveDeleteLink meta value 42 $thisJSDeleteMetaValue = get_post_meta( $post->ID, "_jsRemoveDeleteLink", true ); 43 // if value == yes then remove link 44 if( $thisJSDeleteMetaValue == "yes" || $post->ID == 4 ){ unset( $actions["trash"] ); } 45 // send links back to wp 46 return $actions; 47 48 } add_filter("post_row_actions", "js_remove_delete_link_from_post_list",10,2); 49 add_filter("page_row_actions", "js_remove_delete_link_from_post_list",10,2); 50 51 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 52 /// remove the delete link edit post/page page 53 54 function js_remove_delete_link_from_post_edit_page(){ 55 56 /* when reasearching and looking at wp-admin/includes/meta-boxes.php. There is no way that I can see that will allow us to 57 remove the Move to Trash link in the publish box. So this is a temporarry fix untill we can find a better way to acomplush 58 this feature. */ 59 60 $currentJSPostID = (int)$_GET["post"]; 61 // get this posts jsRemoveDeleteLink meta value 62 $thisJSDeleteMetaValue = get_post_meta( $currentJSPostID, "_jsRemoveDeleteLink", true ); 63 // if value == yes then remove link 64 if( $thisJSDeleteMetaValue == "yes" && ( get_post_type( $currentJSPostID ) == "page" || get_post_type( $currentJSPostID ) == "post" ) ){ 65 //$postTypeIs = ""; 66 //if ( get_post_type( $currentJSPostID ) ){ } 67 ?><style>#delete-action{ display:none; } #js-remove-delete-message{ position:absolute; bottom:11px; }</style> 68 <div id="js-remove-delete-message">You cannot delete this <? echo get_post_type( $currentJSPostID ); ?> </div><? 69 } 70 71 } add_action( 'post_submitbox_start', 'js_remove_delete_link_from_post_edit_page' ); 72 73 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 74 /// add check box to the screen options page 75 76 function js_remove_delete_link_add_checkBox_to_screen_settings($current, $screen){ 77 78 /* found this example in the dont-break-the-code-example */ 79 if ( isset( $_GET["post"] ) ){ 80 81 $currentJSPostID = (int)$_GET["post"]; 82 // if this post is a page or a post then add the check box 83 if( in_array( $screen->id, array("post", "page") ) && ( get_post_type( $currentJSPostID ) == "page" || 84 get_post_type( $currentJSPostID ) == "post" ) && current_user_can("administrator") ){ 85 86 // get this posts jsRemoveDeleteLink meta value 87 $thisJSDeleteMetaValue = get_post_meta( $currentJSPostID, "_jsRemoveDeleteLink", true ); 88 // if value == yes then add checkbox to the screen settings tab 89 $addCheckBoxCode = "<h5>Remove the ability to delete this ".get_post_type( $currentJSPostID )."</h5>"; 90 91 if ( $thisJSDeleteMetaValue == "yes" ){ $checked = ' checked="checked" '; } 92 93 $addCheckBoxCode .= '<input type="checkbox" id="jsRemoveDeleteLink" name="jsRemoveDeleteLink"'.$checked.'/> '; 94 $addCheckBoxCode .= '<label for="jsRemoveDeleteLink"> '; 95 $addCheckBoxCode .= 'Remove Trash Link'; 96 $addCheckBoxCode .= '</label> '; 97 return $addCheckBoxCode; 98 99 } else { return; } 100 101 } 102 103 } add_filter('screen_settings', 'js_remove_delete_link_add_checkBox_to_screen_settings', 10, 2); 104 105 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 106 // add jquery function to admin head to save the remove delete link meta for this post 107 108 function js_remove_delete_link_add_jquery_to_head(){ 109 110 /* add jquery to the head in-order to save the checkbox option */ 111 if ( isset( $_GET["post"] ) && current_user_can("administrator") ){ 112 113 $currentJSPostID = $_GET["post"]; ?> 114 <script type="text/javascript" language="javascript"> 115 jQuery(document).ready(function(){ 116 // when the checkbox is clicked save the meta option for this post 117 jQuery('#jsRemoveDeleteLink').click(function() { 118 var isJSDeleteisChecked = 'no'; 119 if ( jQuery('#jsRemoveDeleteLink').attr('checked') ){ isJSDeleteisChecked = 'yes'; } 120 jQuery.post( ajaxurl, 121 'action=jsRemoveDeleteLink_save&post=<?php echo $currentJSPostID; ?>&jsRemoveDeleteLink=' + isJSDeleteisChecked, 122 function(response) { // hide or show trash link 123 if ( response == "yes" ){ // hide delete link 124 jQuery('#delete-action').hide( function() { 125 var addThisAboveDelete = '<div id="js-remove-delete-message" style="position:absolute; bottom:11px;">'; 126 addThisAboveDelete += 'You cannot delete this <? echo get_post_type( $currentJSPostID ); ?> </div>'; 127 jQuery(addThisAboveDelete).prependTo('#major-publishing-actions'); }); 128 } else if ( response == "no" ){ // show delete link 129 jQuery('#js-remove-delete-message').remove(); jQuery('#delete-action').show(); } }); }); }); </script> <? 130 131 } 132 133 } add_action( 'admin_head', 'js_remove_delete_link_add_jquery_to_head' ); 134 135 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 136 /// add ajax call to wp in order to save the remove delete post link 137 138 function js_remove_delete_link_add_ajax_call_to_wp(){ 139 140 /* found this example in the dont-break-the-code-example */ 141 $jsRemoveDeleteLink = $_POST['jsRemoveDeleteLink']; 142 $currentJSPostID = (int)$_POST["post"]; 143 if( !empty( $currentJSPostID ) && $jsRemoveDeleteLink !== NULL ) { 144 update_post_meta($currentJSPostID, "_jsRemoveDeleteLink", $jsRemoveDeleteLink); 145 echo $jsRemoveDeleteLink; 146 } else { echo $jsRemoveDeleteLink; } exit; 147 148 } add_action('wp_ajax_jsRemoveDeleteLink_save', 'js_remove_delete_link_add_ajax_call_to_wp'); 149 150 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 151 /// when we deactivate the plugin do this 152 153 function remove_js_disable_delete_post() { delete_option('jsDisableDeletePost'); } 154 register_deactivation_hook( __FILE__, 'remove_js_disable_delete_post' ); 155 156 /// end function code 157 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 27 28 Note: go here http://reactivedevelopment.net/disable-delete-post-page for documentation 29 or for paid support go here http://www.reactivedevelopment.net/contact/ 30 31 * 32 33 Activation Instructions 34 35 1. Download the disable-delete-post-or-page-link-wordpress-plugin.zip file to your computer. 36 2. Unzip the file. 37 3. Upload the `disable-delete-post-or-page-link-wordpress-plugin` folder to your `/wp-content/plugins/` directory. 38 4. Activate the plugin through the 'Plugins' menu in WordPress. 39 40 * 41 42 Change log 43 44 01. updated public function reference ver 0.2 | 01/04/2014 45 46 * 47 **/ 48 49 /** 50 51 when we activate the plugin do this 52 53 * 54 * @package Disable Delete Post or Page 55 * @subpackage install_js_disable_delete_post 56 * @since 1.0 57 */ 58 59 function install_js_disable_delete_post() { 60 61 $currentJSDeletePostOption = unserialize( get_option( 'jsDisableDeletePost', '' ) ); 62 if ( empty( $currentJSDeletePostOption ) ){ 63 64 add_option( 'jsDisableDeletePost', 'yes', '', 'yes' ); 65 66 } 67 68 } register_activation_hook( __FILE__, 'install_js_disable_delete_post' ); 69 70 /** 71 72 remove the delete link from the page/posts list 73 74 * 75 * @package Disable Delete Post or Page 76 * @subpackage js_remove_delete_link_from_post_list 77 * @since 1.0 78 */ 79 80 function js_remove_delete_link_from_post_list( $actions, $post ){ 81 82 // get this posts jsRemoveDeleteLink meta value 83 $thisJSDeleteMetaValue = get_post_meta( $post->ID, '_jsRemoveDeleteLink', true ); 84 if( $thisJSDeleteMetaValue == 'yes' || $post->ID == 4 ){ 85 86 unset( $actions[ 'trash' ] ); 87 88 } return $actions; 89 90 } add_filter( 'post_row_actions', 'js_remove_delete_link_from_post_list', 10, 2 ); 91 add_filter( 'page_row_actions', 'js_remove_delete_link_from_post_list', 10, 2 ); 92 93 /** 94 95 remove the delete link edit post/page page 96 97 * 98 * @package Disable Delete Post or Page 99 * @subpackage js_remove_delete_link_from_post_edit_page 100 * @version 2.0 101 * @since 1.0 102 */ 103 104 function js_remove_delete_link_from_post_edit_page(){ 105 106 /* when reasearching and looking at wp-admin/includes/meta-boxes.php. There is no way that I can see that will 107 allow us to remove the Move to Trash link in the publish box. So this is a temporarry fix untill we can find 108 a better way to acomplish this feature. */ 109 110 $currentJSPostID = intval( $_GET[ 'post' ] ); 111 if ( $currentJSPostID > 0 ){ 112 113 // get this posts jsRemoveDeleteLink meta value 114 $thisJSDeleteMetaValue = get_post_meta( $currentJSPostID, '_jsRemoveDeleteLink', true ); 115 116 // if value == yes then remove link 117 if( $thisJSDeleteMetaValue == 'yes' && ( get_post_type( $currentJSPostID ) == 'page' 118 || get_post_type( $currentJSPostID ) == 'post' ) ){ 119 120 ?><style>#delete-action{ display:none; } #js-remove-delete-message{ position:absolute; bottom:11px; }</style> 121 <div id="js-remove-delete-message"><? _e( 'You cannot delete this' ); ?> <? 122 echo get_post_type( $currentJSPostID ); ?> </div><? 123 124 } 125 126 } 127 128 } add_action( 'post_submitbox_start', 'js_remove_delete_link_from_post_edit_page' ); 129 130 /** 131 132 add check box to the screen options page 133 134 * 135 * @package Disable Delete Post or Page 136 * @subpackage js_remove_delete_link_add_checkBox_to_screen_settings 137 * @version 2.0 138 * @since 1.0 139 */ 140 141 function js_remove_delete_link_add_checkBox_to_screen_settings( $current, $screen ){ 142 143 /* found this example in the dont-break-the-code-example */ 144 $currentJSPostID = intval( $_GET[ 'post' ] ); 145 if ( $currentJSPostID > 0 ){ 146 147 // if this post is a page or a post then add the check box 148 if( in_array( $screen->id, array( 'post', 'page' ) ) && ( get_post_type( $currentJSPostID ) == 'page' 149 || get_post_type( $currentJSPostID ) == 'post' ) && current_user_can( 'administrator' ) ){ 150 151 // get this posts jsRemoveDeleteLink meta value 152 $thisJSDeleteMetaValue = get_post_meta( $currentJSPostID, '_jsRemoveDeleteLink', true ); 153 154 // if value == yes then add checkbox to the screen settings tab 155 $addCheckBoxCode = '<h5>' . __( 'Remove the ability to delete this' ) . get_post_type( $currentJSPostID ) . '</h5>'; 156 157 if ( $thisJSDeleteMetaValue == 'yes' ){ $checked = ' checked="checked" '; } 158 $addCheckBoxCode .= '<input type="checkbox" id="jsRemoveDeleteLink" name="jsRemoveDeleteLink"' . $checked . '/>' 159 . '<label for="jsRemoveDeleteLink"> ' 160 . __( 'Remove Trash Link' ) 161 . '</label> '; 162 163 return $addCheckBoxCode; 164 165 } else { return; } 166 167 } 168 169 } add_filter( 'screen_settings', 'js_remove_delete_link_add_checkBox_to_screen_settings', 10, 2 ); 170 171 /** 172 173 add jquery function to admin head to save the remove delete link meta for this post 174 175 * 176 * @package Disable Delete Post or Page 177 * @subpackage js_remove_delete_link_add_jquery_to_head 178 * @version 2.0 179 * @since 1.0 180 */ 181 182 function js_remove_delete_link_add_jquery_to_head(){ 183 184 /* add jquery to the head in-order to save the checkbox option */ 185 $currentJSPostID = intval( $_GET[ 'post' ] ); 186 if ( $currentJSPostID > 0 && current_user_can( 'administrator' ) ){ ?> 187 188 <script type="text/javascript" language="javascript"> 189 190 jQuery( document ).ready( function(){ 191 192 // when the checkbox is clicked save the meta option for this post 193 jQuery( "#jsRemoveDeleteLink" ).click( function() { 194 195 var isJSDeleteisChecked = "no"; 196 if ( jQuery( "#jsRemoveDeleteLink" ).attr( "checked" ) ){ isJSDeleteisChecked = "yes"; } 197 jQuery.post( ajaxurl, 198 199 "action=jsRemoveDeleteLink_save&post=<?php echo $currentJSPostID; ?>&jsRemoveDeleteLink=" + isJSDeleteisChecked, 200 201 function(response) { // hide or show trash link 202 203 if ( response == "yes" ){ // hide delete link 204 205 jQuery( "#delete-action" ).hide( function() { 206 207 var addThisAboveDelete = '<div id="js-remove-delete-message" style="position:absolute; bottom:11px;">'; 208 addThisAboveDelete += "<? _e( 'You cannot delete this' ); ?> <? echo get_post_type( $currentJSPostID ); ?> </div>"; 209 jQuery( addThisAboveDelete ).prependTo( "#major-publishing-actions" ); 210 211 }); 212 213 } else if ( response == "no" ){ // show delete link 214 215 jQuery( "#js-remove-delete-message" ).remove(); 216 jQuery( "#delete-action" ).show(); 217 218 } 219 220 }); 221 222 }); 223 224 }); 225 226 </script> <? 227 228 } 229 230 } add_action( 'admin_head', 'js_remove_delete_link_add_jquery_to_head' ); 231 232 /** 233 234 add ajax call to wp in order to save the remove delete post link 235 236 * 237 * @package Disable Delete Post or Page 238 * @subpackage js_remove_delete_link_add_ajax_call_to_wp 239 * @version 2.0 240 * @since 1.0 241 */ 242 243 function js_remove_delete_link_add_ajax_call_to_wp(){ 244 245 /* found this example in the dont-break-the-code-example */ 246 $jsRemoveDeleteLink = $_POST[ 'jsRemoveDeleteLink' ]; 247 $currentJSPostID = intval( $_GET[ 'post' ] ); 248 249 if( !empty( $currentJSPostID ) && $jsRemoveDeleteLink !== NULL ) { 250 251 update_post_meta( $currentJSPostID, '_jsRemoveDeleteLink', $jsRemoveDeleteLink ); 252 echo $jsRemoveDeleteLink; 253 254 } else { echo $jsRemoveDeleteLink; } exit; 255 256 } add_action( 'wp_ajax_jsRemoveDeleteLink_save', 'js_remove_delete_link_add_ajax_call_to_wp' ); 257 258 /** 259 260 when we deactivate the plugin do this 261 262 * 263 * @package Disable Delete Post or Page 264 * @subpackage remove_js_disable_delete_post 265 * @since 1.0 266 */ 267 268 function remove_js_disable_delete_post() { 269 270 delete_option( 'jsDisableDeletePost' ); 271 272 } register_deactivation_hook( __FILE__, 'remove_js_disable_delete_post' ); 273 274 /** 275 276 End code 277 278 */ 158 279 159 280 ?> -
disable-delete-post-or-page-link-wordpress-plugin/trunk/readme.txt
r554408 r1098621 1 1 === Plugin Name === 2 2 Contributors: jeremyselph 3 Donate link: http:// www.reactivedevelopment.net/snippets/disable-delete-post-page/3 Donate link: http://reactivedevelopment.net/disable-delete-post-page 4 4 Tags: delete post, delete, delete page 5 5 Requires at least: 3.1.1 6 Tested up to: 3.4.06 Tested up to: 4.1.1 7 7 Stable tag: 4.3 8 License: GPLv 2or later9 License URI: http://www.gnu.org/licenses/gpl- 2.0.html8 License: GPLv3 or later 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 11 11 Allows the administrator to remove the delete post link from the page lists and from the publish box in edit view.
Note: See TracChangeset
for help on using the changeset viewer.