Hot answers tagged

7

Disabling the sitemap is easy, just add this line to your functions.php: add_filter( 'wp_sitemaps_enabled', '__return_false' ); Removing specific posts goes like this: add_filter( 'wp_sitemaps_posts_query_args', function( $args, $post_type ) { if ( 'post' !== $post_type ) { return $args; } $args['post__not_in'] =...


6

I just encountered the same issue. After quick analysis I found that this file is allowing remote access of your website to a third party which is pretty much dangerous. This is found in wordpress websites that are using nulled wordpress plugins. This file is being generated from these two files bundled inside nulled plugins: rms-script-ini.php rms-...


4

Explanation: The issue you are likely facing is that you are trying to add your ajax actions from within the widget itself that may be instantiated on the elementor/widgets/widgets_registered hook. If so, this is hook elementor/widgets/widgets_registered is too late and do_action( "wp_ajax_{$action}" ) and do_action( "wp_ajax_nopriv_{$action}" ) have ...


4

So there are two parts to your question: How to run code when your plugin is activated How to send an email For item 1 I searched for 'wordpress plugin activation hook' and found https://developer.wordpress.org/plugins/plugin-basics/activation-deactivation-hooks/ which describes this hook so you can call your own fucntion when a plugin is activated: ...


3

MU plugins don't 'activate', or 'deactivate'. They're just present or not present. So you'll need a different approach. One option would be to just perform your activation functions on init, and store a record in the database to say whether or not it's already been done: function activate_mjmc_core() { if ( '1' === get_option( 'mjmc_activated' ) ) { ...


3

You can start with something like this: https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[page]=1&request[per_page]=400 I think it's self-explanatory.


3

You must specify in the roots sage theme composer.json the runtime where autoload can find the classes. "autoload": { "psr-4": { "App\\": "app/", "App\\Blocks\\": "app/Blocks/", "Itineris\\AcfGutenblocks\\": "../../plugins/acf-gutenblocks/src/", } } Don't forget to run composer dump-autoload


3

If you want to load it after jQuery, you can use script dependency... (3rd param) For example if your scripts depends on jQuery, you can use: wp_enqueue_script( 'login-script', plugin_dir_url( __FILE__ ) . 'scripts.js', array( 'jquery' ), null, true );


3

the async property is marked as protected, so that usually signifies that it is related more to your implementation's details rather than functionality. Ideally you would write your tests to test the public methods you have exposed. Testing that the class property you set in the constructor of one class is an instanceof what was initialized doesn't provide ...


3

It's not possible with just WordPress to schedule code to run in the background at a specific time. WordPress, like most (if not all) PHP web applications, only actually runs in response to a URL being accessed, and a request being made to the server. For a scheduled event to run at a certain time, you would need to have something running on the server, such ...


3

You can use script_loader_tag filter to fulfill your requirement. add below code in your active theme's functions.php file. it will add extra parameter in your script tag. function add_attribute_to_script_tag($tag, $handle) { # add script handles to the array below $scripts_to_defer = array('wpfrank-ptbw-pinit-js'); foreach($scripts_to_defer as $...


3

Always use the upload directory to store files, nothing else. There are two reasons: Plugin directories are replaced on plugin updates, so your custom files will be deleted. The upload directory is the only one where you can expect write access. For example, I'm updating my plugins via composer, and there is no write access to that directory before and ...


3

No, it is not safe to resize columns in WP core tables, or to alter them. When you next update WordPress, the update process will alter the tables to the official table schema, truncating all your GUIDs and breaking them. Instead, you need to contact the support route for the plugin so that they can fix this. They shouldn't be reusing GUIDs to store URLs ...


3

Instead of using raw DOM nodes, use the WP Element wrapper components and build it with wp scripts For example here is an ESNext block using modern JS: edit() { return ( <div style={ blockStyle }> Hello World, step 1 (from the editor). </div> ); }, And again using raw JS without ...


3

The solution is simple, don't echo the result of that function, there is no result to echo. echo the_post_thumbnail(array(155,55)); Is equivalent to something like this: echo ''; the_post_thumbnail(array(155,55)); Functions that begin with the_ in WP don't return things, they output things. Some of them let you pass a parameter that lets them return ...


3

Consider plugin A: $A_message; add_action('plugins_loaded', function() { do_action('plugin-A:init'); }); // Hooks allow B to access A (both during initialization of A and elsewhere in WordPress) without having to check if A exists. add_filter('plugin-A:set', function($msg) { $A_message = $msg; }, PHP_INT_MAX); add_filter('plugin-A:get', function(...


3

A very helpful question, I think. There are two plugins, for the discussions let's say: ToBeDeprecated Plugin, and ToBeUplifted Plugin There could be many ways, but these are the points that come to my mind first: Before the Upgrade Seemless Migration In the code of the ToBeUplifted plugin, you should ensure a seamless migration process from the ...


2

The suggested answer by Arnis works if you are using the same form throughout your whole site, however, it will inject text in forms which don't have all the fields targeted in your functions.php file. For a new suggested solution: Setting the input or textarea "autocomplete" attribute to a random variable that is not a standard value seems to do the trick ...


2

As @jacob suggest, you can add subscriber role into that array using add_filter . add below code in active theme's functions.php file. add_filter( 'wf_user_permission_roles', 'wf_user_permission_roles_callback' ) ; function wf_user_permission_roles_callback( $roles ) { $roles[] = 'subscriber'; return $roles; }


2

This sounds like it's probably caused by mod-evasive (or similar) plugin in Apache (or similar), blocking multiple consecutive requests as it thinks you are trying to run a denial of service (DOS) attack against the server. Try disabling any security plugins (Apache / web server ones, not WordPr


2

I hate to be the bearer of bad news, but there is no general plugin update API, there is only the one Core uses when talking to .org, and it's the only implementation. Some plugins use filters and hooks to add their own checks to this system, but most don't, or provide their own parallel bespoke checks. These are all highly dependent on the plugins ...


2

You can temporarily detach the function from the hook. // THIS IS MY PROBLEM LINE, i USE Apply Filters for post content.... $priority = has_filter('the_content', ['TableOfContents', 'writeTOC'] ); if ( $priority !== false ) remove_filter('the_content', ['TableOfContents', 'writeTOC'], $priority ); $meta = apply_filters('the_content'...


2

if(!function_exists('remove_my_action')){ function remove_my_action(){ remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 ); remove_action( 'storefront_header', 'storefront_header_container_close', 41 ); remove_action( 'storefront_header', 'storefront_primary_navigation_wrapper', 42 ); remove_action( ...


2

Found out you can get the container post ID with $_POST['_wpcf7_container_post'])


2

You can get the post ID from array variable $posted_data the form was send from if ($submission) { $posted_data = $submission->get_posted_data(); print_r($posted_data) } if you do a print_r on it you will get something like this: Array ( [_wpcf7] => 20 [_wpcf7_version] => 5.1.6 [_wpcf7_locale] => en_US [...


2

Due to a backwards-incompatible change in version 5.2, you can no longer retrieve the form's meta data using get_posted_data(). Instead, you can use the id value in the array returned by get_current(): $contact_form = WPCF7_ContactForm::get_current(); $contact_form_id = $contact_form -> id;


2

Your problem has nothing to do with apply_filters, it's a basic PHP mistake: public function init (){ $filter_fields = apply_filters('tbg_reg_fields', $this->fields); } Here, you create a brand new variable in the init method scope named $filter_fields, then never use it. $this->filter_fields and $...


2

WordPress.org’s Plugin Directory works based on the information found in the field Stable Tag in the readme. When WordPress.org parses the readme.txt, the very first thing it does is to look at the readme.txt in the /trunk directory, where it reads the “Stable Tag” line. If the Stable Tag is missing, or is set to “trunk”, then the version of the plugin in /...


2

Your analysis of the problem is absolutely right. By having separate autoloaders in the theme and plugin you'll run into conflicts and only the first one being loaded. There is no easy and general solution to this, but if you control the whole stack the best solution probably is to put the whole site including WP under composer management and define the ...


2

A fast and easy solution is to fetch the slug with $_GET['page']. Don't forget to do some safety checks on the query after getting it. Also, while i'm on it, to make the submenu items show up below your top level you need to change the first property of add_submenu_page to your top level slug. add_action( 'admin_menu', 'MyPlugin_AddAdminMenus' ); function ...


Only top voted, non community-wiki answers of a minimum length are eligible