How to edit/delete single row items in a table on my own menu page

WordPress allows you to use a class called wpdb Here is an example of how you would use it function add_to_db() { global $wpdb; $your_table_name = $wpdb->prefix . “wp-LINKS-list-table”; $the_value=”123″; $wpdb->insert( $your_table_name, array(‘column_name’ => $the_value,)); this will insert 123 into the column_name. You can read more here Note: If you are creating a menu page … Read more

wp_dropdown_pages() in theme admin page

grrr.really annoying, 2hrs and then i found it myself $args = array( ‘echo’ => 1, ‘selected’ => $home_galleryselect, ‘name’ => ‘theme_option[home_galleryselect]’); wp_dropdown_pages($args);

Adding markup to column text in “Edit Pages” admin page

I found that there is a filter, manage_posts_columns (and a related manage_pages_columns), that lets you modify the column headers on the “All Posts” admin screen. Using this filter is pretty simple, as the filtering function takes in an associative array with the short name of the column as a key and the heading as the … Read more

Add text to wordpress admin ‘Add Post’ edit

It’s not that hard, you can use the all_admin_notices-hook, which appears beneath the Post Updated/Saved, etc. messages box. Wrapped up in a plugin: <?php ! defined( ‘ABSPATH’ ) AND exit; /** Plugin Name: (#64933) »kaiser« Add post/page note */ function wpse64933_add_posttype_note() { global $post, $pagenow; // Abort in certain conditions, based on the global $pagenow … Read more

How To Create User Specific Admin User Pages?

You can add a new page using add_(sub)menu_page();. WordPress is pretty kind in this case and offers tons of hooks, filters and higher level API functions that help you going around this. Let’s just use add_users_page(); and hook into admin_menu. Example plugin It adds an admin page that has the user_login as slug. Simply drop … Read more

Create a Meta Box in the Admin User Screen?

Well, as you already know, meta boxes are for post types only… What you can do is to customize the heck out of that screen. What follows is the code I used on a client’s custom theme. Originally, it was used with the action hook admin_print_scripts-profile.php (which could also be added bellow). /functions.php: add_action( ‘admin_print_scripts-user-new.php’, … Read more

Restrict dashboard access for specific user roles to specific actions

This is how I ended up solving this issue. Originally I used this code for the link to delete an individual post: <?php if( !(get_post_status() == ‘trash’) ) : ?> <a class=”delete-post” onclick=”return confirm(‘Are you sure you wish to delete post: <?php echo get_the_title() ?>?’)”href=”https://wordpress.stackexchange.com/questions/78144/<?php echo get_delete_post_link( get_the_ID() ); ?>”>Delete</a> <?php endif; ?> After checking … Read more

Is it safe to post form data via Ajax to the settings api? Am I missing something?

WordPress does not natively use Ajax submits with Settings API, so there isn’t really best practice for it. I remember scbFramework having such option, but it was removed. Essentially there is nothing inherently more insecure to such submit, you should treat form data as untrusted regardless of submit method and appropriately sanitize and validate it … Read more

how to redirect to url.com/wp-admin if url.com/admin is typed in?

Hook into template_redirect, inspect the request URI, and redirect to the return value of admin_url(). add_action( ‘template_redirect’, function() { $request = untrailingslashit( strtolower( $_SERVER[‘REQUEST_URI’] ) ); if ( ‘admin’ === $request ) { wp_redirect( admin_url() ); exit; } }); Note: always use admin_url() and the other built-in URL functions, because they will take care of … Read more