How can I target WordPress 3.8 new interface MP6 with CSS?

While it’s not specific to MP6 (I am not following its development) and its CSS, to me your question sounds like “how to check that WP version is equal to greater than one some feature was introduced in?”. So I would just examine content of $wp_version global. If it’s 3.8 feature then anything with fitting … Read more

Filter translations (gettext strings) on specific admin pages

According with the codex, get_current_screen() has to be used later than admin_init hook. After a few tests, it seems that the safiest way is to use current_screen action hook instead of get_current_screen(): add_action(‘current_screen’, ‘current_screen_callback’); function current_screen_callback($screen) { if( is_object($screen) && $screen->post_type == ‘mycpt’ ) { add_filter( ‘gettext’, ‘theme_change_comments_label’, 99, 3 ); } } function theme_change_comments_label( … Read more

Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”

it seems the latter only accepts x-www-form-urlencoded That’s not completely true. WordPress admin-ajax.php takes the action from $_REQUEST[‘action’] and $_REQUEST is equal to: array_merge($_POST, $_GET); But what many people don’t realize is that $_GET in PHP is not the data was sent to page using HTTP GET method, in fact, you can use whatever HTTP … Read more

How do I load a CSS style into WordPress admin area only?

Just hook your callback into admin_print_styles, i.e.: add_action( ‘admin_print_styles’, ‘mytheme_add_init’ ); Alternately, you could add an is_admin() conditional wrapper inside your callback, and hook into wp_enqueue_scripts: function mytheme_add_init() { if ( is_admin() ) { $file_dir=get_bloginfo(‘template_directory’); wp_enqueue_style(“functions”, $file_dir.”/scripts/custom.css”, false, “1.0”, “all”); wp_enqueue_script(“rm_script”, $file_dir.”/scripts/custom.js”, false, “1.0”); } } add_action( ‘wp_enqueue_scripts’, ‘mytheme_add_init’ ); But the absolute best approach … Read more

Disable Media Uploads to non Admin Users

Here are 2 methods: Method 1: Remove the upload_files capability from the respective roles. e.g. removing it from author: $role = get_role( ‘author’ ); $role->remove_cap( ‘upload_files’ ); This is saved to the database so it should only happen once, not on every page load. Removing it from the editor role should be the same albeit … Read more

Settings API – adding setting fields dynamically?

It sounds like you would need a way to get those dynamic fields into the my_options function each time it’s called. You could try creating your own filter to use: function my_options() { $myarray = apply_filters( ‘my_get_options_dynamically’, array() ); $count = 0; foreach($myarray as $something) { $count++; $options[] = array( ‘id’ => ‘something’. $count, ‘title’ … Read more

How to save dismissable notice state in WP 4.2?

There’s no need for a library, it’s fairly straightforward to accomplish. If you are coding your own plugin (which it appears you are), then you can do this in a fairly lightweight way: A slightly modified version of the notice, which checks if it’s been dismissed before displaying, and stores the “type” of notice in … Read more

How can I change the admin search posts fields?

It is possible, but you’ll have to play a little bit with the actual query. As always, the furious posts_clauses filter comes to action: function wpse_alter_posts_search( $pieces ) { global $wpdb; // Make the input save $search_string = like_escape( $_GET[‘s’] ); // Your new WHERE clause $where = $wpdb->prepare( “$wpdb->postmeta.%s LIKE %s”, ‘YOUR_COLUMN’, // Should … Read more

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