Prevent from deleting any user role but subscriber

If you mean the delete button on the user list at /wp-admin/users.php, then that button is created by the WP_Users_List_Table class around (currently) line 256. If you look a little further down– a few lines– you will see a filter called user_row_actions. You can use that to hide the ‘delete’ link. add_filter( ‘user_row_actions’, function($actions, $user_object) … Read more

Does WordPress Allow Blank/Empty Comment Submissions In WordPress?

Short answer: It doesn’t, but you can get around this: add_filter(‘comment_form_field_comment’, ‘my_comment_form_field_comment’); function my_comment_form_field_comment($default){ return false; } add_action(‘pre_comment_on_post’, ‘my_pre_comment_on_post’); function my_pre_comment_on_post($post_id){ $some_random_value = rand(0, 384534); $_POST[‘comment’] = “Default comment. Some random value to avoid duplicate comment warning: {$some_random_value}”; } If you want this only for certain pages, then you should create a custom page template, … Read more

Multisite: setting theme and options when a new blog is created

The best hook I can find is wpmu_new_blog (line 1086, wp-includes/ms-functions.php, wpmu_create_blog()) – it passes 6 arguments like so; do_action( ‘wpmu_new_blog’, $blog_id, $user_id, $domain, $path, $site_id, $meta ); $meta is an array of initial site options, not to be confused with the options generated by populate_options(). Programatically creating nav menus may prove to be a … Read more

Hide a page in the admin end without a plugin?

you can use parse_query filter hook to exclude your pages using post__not_in attribute add_filter( ‘parse_query’, ‘exclude_pages_from_admin’ ); function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow==’edit.php’ && $post_type ==’page’) { $query->query_vars[‘post__not_in’] = array(’21’,’22’,’23’); } } this will exclude pages with the ids of 21,22,23 and to make sure this pages will not be included on … Read more

Admin Post Update Redirection to Posts Screen

Use the redirect_post_location filter and admin_url() function. add_filter( ‘redirect_post_location’, ‘wpse_124132_redirect_post_location’ ); /** * Redirect to the edit.php on post save or publish. */ function wpse_124132_redirect_post_location( $location ) { if ( isset( $_POST[‘save’] ) || isset( $_POST[‘publish’] ) ) return admin_url( “edit.php” ); return $location; } To redirect to a different url, add everything after the … Read more

Add a wp editor to custom plugin and save data

Solved it! Hope somebody else can use it or it answers their problem. If there is a better way please share and tell why. $editor_id = ‘custom_editor_box’; $uploaded_csv = get_post_meta( $post->ID, ‘custom_editor_box’, true); wp_editor( $uploaded_csv, $editor_id ); To save the data: function save_wp_editor_fields(){ global $post; update_post_meta($post->ID, ‘custom_editor_box’, $_POST[‘custom_editor_box’]); } add_action( ‘save_post’, ‘save_wp_editor_fields’ ); And that’s … Read more

Generate custom output for page/URL in a plugin

<?php /* Plugin Name: Custom output Description: A module to test the custom output. To test: http://your_wordpress_site.com/customop_uri_path Version: 1.0 Author: Danilo Silva Author URI: http://danilocgsilva.me */ // Write a new permalink entry on code activation register_activation_hook( __FILE__, ‘customop_activation’ ); function customop_activation() { customop_custom_output(); flush_rewrite_rules(); // Update the permalink entries in the database, so the permalink … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)