admin_url in plugins

First rule of wordpress development is to always use a core API if one is available, there is usually a good reason for its existence. In this case, you are assuming something about how files are called and the URLs they are in. For an example were such an assumption will fail, is the (rarely … Read more

Wrong wp-admin URL

Eventually, I found the reason of this weird behaviour. It is caused by the JavaScript embedded in wp_admin_canonical_url() (https://developer.wordpress.org/reference/functions/wp_admin_canonical_url/) The URL is determined by this piece of code $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’] where the latter one returns wp-admin instead of hello/wp-admin. By manipulating the value in $_SERVER[‘REQUEST_URI’], I can successfully get the correct behaviour in admin … Read more

Reusable content block

if you’re using ACF, create an options page and then add a field there. Then present that data in a side widget by echoing out the field. once the field is created you can call it with this code: <?php the_field(‘page_content’, ‘option’); ?> I like to add it to a function function rt_show_field() { $field … Read more

using wp_sprintf at wordpress option page,

When it comes to user-defined strings, it’s best to use a placeholder or “merge tag” – so on your settings page, inform the user they can use e.g. {blogname} And then in your code: $message = get_option( ‘option_name’ ); $message = str_replace( ‘{blogname}’, get_bloginfo( ‘name’ ) ); This is less error prone & clearer to … Read more

How To Reset Ownership And Permissions of Wp-Content Folder, In Order to Fix HTTP Error When Uploading Images to WordPress Media Library

try increasing WordPress Memory Limit to 256M The most common cause of this error is lack of memory available for WordPress to use. To fix this, you need to increase the amount of memory PHP can use on your server. You can do this by adding the following code to your wp-config.php file. define( ‘WP_MEMORY_LIMIT’, … Read more

Uncheck the box “Send User Notification” by default on new-user.php

There does not seem to be an easy overwrite without replicating the whole user interface. So the quickest solution might be to un-check the checkbox via JavaScript: add_action(‘admin_footer’, ‘uncheck_send_user_notification’); function uncheck_send_user_notification() { $currentScreen = get_current_screen(); if (‘user’ === $currentScreen->id) { echo ‘<script type=”text/javascript”>document.getElementById(“send_user_notification”).checked = false;</script>’; } } The script is only injected on the user-new.php … Read more