Why are admin scripts not printed

Use the admin_enqueue_scripts hook instead of admin_init Note: you should use hooks that target admin pages as specifically as possible. e.g.: Plugins: Use the admin_print_scripts-{plugin-page} hook Themes: Use the admin_print_scripts-{theme-page} hook (where {theme-page} is whatever string you use in the add_theme_page() call) Custom Post-Type Edit Page: Use the admin_print_scripts-edit.php hook, For Custom Post Types, inside … Read more

How to Remove All Widgets from Dashboard?

From this Q&A, I’ve learned about the global variable $wp_meta_boxes. And over there is also the code to remove the default meta boxes. After examining the variable, this is the code I wrote to remove all Dashboard Widgets, including the ones added by plugins: add_action(‘wp_dashboard_setup’, ‘wpse_73561_remove_all_dashboard_meta_boxes’, 9999 ); function wpse_73561_remove_all_dashboard_meta_boxes() { global $wp_meta_boxes; $wp_meta_boxes[‘dashboard’][‘normal’][‘core’] = … Read more

Is there un-wp_autop function?

I just ran into this situation. Here is a function I used to undo wpautop. I might be missing something, but this is a good start: function reverse_wpautop($s) { //remove any new lines already in there $s = str_replace(“\n”, “”, $s); //remove all <p> $s = str_replace(“<p>”, “”, $s); //replace <br /> with \n $s … Read more

How do I find all admin users using phpmyadmin?

We can generate the SQL with: $query = new WP_User_Query( [ ‘role’ => ‘Administrator’, ‘count_total’ => false, ] ); echo $query->request; that outputs: SELECT wp_users.* FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) WHERE 1=1 AND ( ( ( wp_usermeta.meta_key = ‘wp_capabilities’ AND wp_usermeta.meta_value LIKE ‘%\”Administrator\”%’ ) ) ) ORDER BY user_login … Read more

Pre-fill fields with content from outside when creating a new post

An empty post is created by get_default_post_to_edit(). This function reads the post_title, content and excerpt values in the $_REQUEST array, and also filters them through default_title, default_content and default_excerpt. By default this function only returns a “fake” $post object, but if the $create_in_db parameter is set to true, it is actually saved in the database … Read more

Removing an admin page added by a 3rd party plugin. Gravity forms in this example

Ok, Eugene’s Answer works in the case of a plugin that doesn’t deals with custom capabilities. http://codex.wordpress.org/Roles_and_Capabilities The WordPress Plugin API allows Roles and Capabilities to be added, removed and changed. Since Plugins might change Roles and Capabilities, just the default ones are addressed in this article. So, if his code works without checking for … Read more

Disable wp-admin console for subscribers

You can remove the Read capability. That will prevent all access to wp-admin. function remove_read_wpse_93843(){ $role = get_role( ‘subscriber’ ); $role->remove_cap( ‘read’ ); } add_action( ‘admin_init’, ‘remove_read_wpse_93843’ ); See the note in the Codex about only needing to run this once. Then you need to hide the admin bar. function hide_admin_wpse_93843() { if (current_user_can(‘subscriber’)) { … Read more

How to change the wording in wp-admin back-end?

You can use the filter admin_post_thumbnail_html: function custom_admin_post_thumbnail_html( $content ) { return $content = str_replace( __( ‘Set featured image’ ), __( ‘Set featured image – 50 pixels by 50 pixels’ ), $content ); } add_filter( ‘admin_post_thumbnail_html’, ‘custom_admin_post_thumbnail_html’ );