I can’t access my admin page after changing main url

Not sure why you would want to make that change, but if worst comes to worst, you can change it back via the database. Assuming you can access your MySQL database directly, simple navigate to the wp_options table and change the value of siteurl and/or home to your desired values. EDIT: Alternatively, if you can … Read more

How to control contextual help section by code?

You could also trigger/simulate the help button being clicked by binding to the ready event. Pre jQuery 1.7 <script type=”text/javascript”> jQuery(document).bind( ‘ready’, function() { jQuery(‘a#contextual-help-link’).trigger(‘click’); }); </script> jQuery 1.7+ (bind deprecated as of 1.7) <script type=”text/javascript”> jQuery(document).on( ‘ready’, function() { jQuery(‘a#contextual-help-link’).trigger(‘click’); }); </script> The difference here is that you’ll see the help section slide down … Read more

Is it possible to set a option, and then redirect to another page directly from a admin notice link?

You could use /wp-admin/admin-post.php. Link: $url = admin_url( ‘admin-post.php?action=somethingunique’ ); print “<a href=”https://wordpress.stackexchange.com/questions/85825/$url”>Update and redirect</a>”; Then you should register a callback for that action: add_action( ‘admin_post_somethingunique’, ‘wpse_85825_callback’ ); And in that callback you can do what you want: function wpse_85825_callback() { if ( current_user_can( ‘manage_options’ ) ) update_option( ‘my_option’, ‘some_value’ ); wp_redirect( admin_url( ‘users.php’ ) … Read more

Restrict access in wp-admin area?

that depends on if you want to redirect users away the you should use init hook since no output or headers are sent before that hook. or if you want to display a nice “You Don’t have the right permissions to access this page” message then you can use the wp_head action hook: //display meassage … Read more

Copy posts from one blog to another in multisite environment

To copy a post from one blog to another you can do something like this: function copy_post_to_blog($post_id, $target_blog_id) { $post = get_post($post_id, ARRAY_A); // get the original post $post[‘ID’] = ”; // empty id field, to tell wordpress that this will be a new post switch_to_blog($target_blog_id); // switch to target blog $inserted_post_id = wp_insert_post($post); // … Read more

Add custom admin menu item for pages using a certain template

If this is what you want: … you can do it like so: Step #1: Add the custom menu item (Retailer Sendout). function add_retailer_sendout_admin_menu() { $slug = ‘edit.php?post_type=page&template=page-retailer-sendout.php’; add_menu_page( ‘Retailer Sendout’, ‘Retailer Sendout’, ‘edit_pages’, $slug, ”, ‘dashicons-admin-page’, 19 ); } add_action( ‘admin_menu’, ‘add_retailer_sendout_admin_menu’ ); Notes: I’m using add_menu_page() to add the menu (which is a … Read more

Remove HTTP: from the site URL and just keep // in it

To remove http: and https: from all links, use the following script: add_action( ‘plugins_loaded’, ‘wpse_232287_init’ ); function wpse_232287_init() { // Initiate the function ob_start( ‘wpse_232287_remove_http’ ); } function wpse_232287_remove_http( $buffer ) { // Check for a Content-Type header, only apply rewriting to “text/html” or undefined $headers = headers_list(); $content_type = null; foreach ( $headers as … Read more