Reading the inside of

If you’re in the admin and you want to “read” the <head /> of the frontend, you can make an internal HTTP request and scrape the response HTML: $url = home_url(); $request = wp_remote_get( $url ); $body = wp_remote_retrieve_body( $request ); $dom = new DOMDocument(); libxml_use_internal_errors( true ); $dom->loadHTML( $body ); $xpath = new DOMXpath( … Read more

How do I access the contents of WordPress Classic editor in admin area with JavaScript?

To get the editor content as a string in the classic editor use this: content = tinymce.activeEditor.getContent(); Taken from https://stackoverflow.com/a/5843951/57482 Note that you should use the APIs provided rather than directly modifying the DOM if you want to modify the content. If you don’t, you won’t update plugins local states in javascript causing problems. Modifying … Read more

Using “add_image_size” to register custom image sizes inside plugins not working

There’s several misunderstandings about how WordPress works here. I noticed that most examples of add_image_size() is done via the after_setup_theme hook. Which means, for it to register, one has to switch theme and reactivate the theme. Firstly, that’s not what it means. The after_setup_theme hook runs on every page load after the theme has been … Read more

$_GET vs get_query_var()

get_query_var() gets variables from the main instance of WP_Query. It’s the equivalent of running global $wp_query; $wp_query->get( ‘posts_per_page’ ); It is not directly related to $_GET in any way. However, WordPress has a list of ‘public’ query variables that will be applied to the main query if they are passed as URL parameters. This is … Read more

PHPUnit Ajax Serialization of ‘Closure’ is not allowed

Figured out that it was the @runTestsInSeparateProcesses annotation in the test class that was causing the error. Not sure why that would cause it. Once I removed it, the test completed successfully. ./vendor/bin/phpunit –group ajax Installing… Running as single site… To run multisite, use -c tests/phpunit/multisite.xml Not running ms-files tests. To execute these, use –group … Read more

Declaration of mandoe_menu_walker::start_el(&$output, $item, $depth, $args) must be compatible with Walker::start_el(…)

An entirely different approach. nav menu item are stored in posts table, so you can technically attach a post_meta into it, even other data like nav item class already stored in post mata table. However this wasn’t easy to do before. but after 5.4.0 release, they have implemented hooks to easily do this. Here’s the … Read more

Update option hook not firing

Because you’re registering your hook inside the function that is rendering the form. When the form is submitted, the update_option action has already run before it gets to displaying the form. Move it outside the function. As it appears you’re using a class, adding the action to the __construct method might be a good idea.

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