PHPUnit Testing Installation Issue
PHPUnit Testing Installation Issue
PHPUnit Testing Installation Issue
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
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
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_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
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
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
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.
The URL is then example.com/myslug (where myslug is the permalink from the page). There is no model parameter however. That happens because you used the wrong parameter for the Page ID: The p parameter corresponds to a fixed page ID I have created. So actually, for the page post type, i.e. Pages, you should use … Read more
The sample code function jon_save_post_webhook($post_id, $post) { // Check to see if autosaving etc., if so ignore if ($post->post_status !== ‘publish’) { return; } if ($post->post_status !== ‘trash’) { return; } /// rest of code Will always return early because while $post->post_status can be “trash” or “publish”, it can never be both at the same … Read more