Can wp_localize_script be used within a shortcode?

Default parameters for wp_enqueue_script will output the script in the wp_head function. Shortcodes typically execute later, when main content is being output. In that case, calling wp_localize_script in the Shortcode handler will have no effect, because the script has already been output. Setting the $in_footer parameter to true when enqueueing the script will delay script … Read more

Plugin exceeds memory limit

The code you use also uses WordPress functions that will first load posts (and other relevant data) in memory first and cache them using object cache. So, to delete 100.000 posts, your code will try to load each post in memory and that can take a lot of memory. I am not sure how high … Read more

redirect on theme switch – WordPress

You could use the after_theme_switch hook to do this, and wp_safe_redirect() works fine to redirect to local urls only. In your callback function check for the $_GET[‘activated’] flag or you may get a “too many redirects” type of error. add_action( ‘after_switch_theme’, ‘my_theme_redirect’ ); function my_theme_redirect() { if( isset( $_GET[‘activated’] ) ) { wp_safe_redirect( admin_url(‘admin.php?page=alecaddd_sunset’) ); … Read more

Undefined property: WP_Post_Type::$ID

Try changing the get_queried_object()->ID to get_queried_object_id(). All the get queried object may not have a property name $ID. So this get_queried_object_id gives the $queried_object_id property value, which gets set on instantiation of WP_Query class. If the $queried_object_id isn’t set then it’ll give you 0.

The Point of Using apply_filters()

The point is to allow developers to customise aspects of your theme or plugin. When calling apply_filters() you provide a name and a value that you want developers to be able to filter. For your example: $array = apply_filters( ‘du/class/method’ array( ‘index’ => ‘value’, ‘index’ => ‘value’, ‘index’ => ‘value’, ‘index’ => ‘value’, ) ); … Read more