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

It is a core WP function, but only after WordPress version 5.5.0. If you're using an older version of WordPress, it won't exist yet. Do this: add_action('admin_init', function() { if ( ! function_exists( 'wp_get_environment_type' ) ) { return; } $environment = wp_get_environment_type(); //... Or, better still, make sure your WordPress installation is up ...


4

import will import those items from a package. const is just an indicator that a variable is a constant, a variable that cannot be reassigned. E.g. const number = 5;. In this case, these 2 lines do exactly the same thing: const useSelect = wp.data.useSelect; const useSelect = window.wp.data.useSelect; The important difference being that if you had included ...


4

I tried to add the toolbar component and I get a syntax error about my brackets First off, JSX is indeed easier and it works like regular HTML, but with the ability to use JavaScript expressions (string literals, variables, function calls, etc.), e.g. <p>Hello, { name }</p> or <p>{ Date.now() }</p>. Now the thing which caused that ...


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

No, you don't need to escape hardcoded values. As I understand it, if the URL doesn't have an input via admin, it should be okay. Not necessarily. There's many more potential sources of potentially malicious (or just accidentally broken) output that need to be accounted for, such as: Translations. Query strings ($_GET) Cookies. WordPress filters. So ...


3

Now I have familiarized myself with the above principles via the documentation and I think I have understood them now I don't know which documentation you read, but you should check the Plugin Security section in the plugin developer's handbook. And there are three main issues I noticed in your code: Before attempting to use a $_GET or $_POST variable, you ...


3

Usually premium plugins that came with the purchase of a theme are updated via an external updater, not the wordpress built-in one. That could be one of the clues. One obvious clue would be that the plugin has some kind of login/licence key system. But when it comes to taking a look in the code, I'm afraid it's not an option cause the paid features can be ...


3

As of WordPress 5.2 (May 2019) this is officially supported Compatibility: WordPress 5.2+ usage as of Jan 2021 is at 76% according to WordPress Stats. How to use: Comprehensive WordPress blog post explaining wp_body_open functionality at https://make.wordpress.org/core/2019/04/24/miscellaneous-developer-updates-in-5-2/ TL;DR Snippet Usage <?php add_action(...


3

Are you using wp multisite? If yes, you can add themes and plugins only from multisite dashboard, and not from site dashboard


3

Yes, and it works exactly the same as any other block, no fake attributes are necessary. When the JS needs to display the component it will make the AJAX request to fetch the markup and pass the attributes with it. The important part to note is that a block in the block editor is still JS. We're just generating some HTML with PHP. When the post is saved, ...


3

It's slightly complicated. The default editor in WordPress is what's properly called the "block editor", but while this editor was being developed it was known as the "Gutenberg" project. The development on Gutenberg was done in the form of a plugin, which people could install for the purposes of testing and contributing. When WordPress 5....


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 ...


3

EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input field As per the updated question and comments this is possible with wp_update_post (or wp_insert_post for a new record) using the meta_input key on the array, e.g.: $metaValues = array( 'key1' => 'value1', 'key2' => 'value2', // ... as many ...


3

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;


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

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(...


2

Unfortunately there is now way to alter the markup of an existing block apart from wrapping it in additional markup: It receives the original block BlockEdit component and returns a new wrapped component. Source: https://developer.wordpress.org/block-editor/developers/filters/block-filters/#editor-blockedit To achieve what you want in the editor currently ...


2

Since this is a multisite you'll have to put the disable password filter in a mu-plugin. Create a file in wp-content/mu-plugins with: <?php add_filter( 'allow_password_reset', '__return_false' ); That should completely disable password recovery. It will affect all sites, not just that one customer's: if that's not what you intended you'll have to add ...


2

SUGGESTIONS I suggest the following: first ensure you are running WordPress version 5.5.* as this version adds the endpoints for /wp/v2/plugins see: New and modified REST API endpoints in WordPress 5.5 using basic authentication issue a request as per the following using curl curl --user username:password https://example.com/wp-json The first request ...


2

use the function get_called_class() public static function init() { add_action( 'wp_enqueue_scripts', array( get_called_class(), 'register_scripts' ) ); }


2

You’ve forgotten the https://. This will happen in any HTML where you don’t add the protocol to a URL. Nothing to do with WordPress. However, you should use esc_url() when outputting user entered values into a link, to make sure the output is a valid URL, even if the user makes this same mistake: <a href="<?php echo esc_url( $item['url'] ); ?>&...


2

To evaluate a meta value as a number, use meta_value_num. Try: $args = array( "fields" => "ids", "meta_key" => "jogador_oficial", "meta_value" => true, "meta_query" => array( "relation" => "AND", "query_one" => ...


2

That's not how register_activation_hook works. register_activation_hook is called only once, when the plugin is activated. CPT's however need to be registered on every single request, not just when the plugin is activated. This is because WP doesn't store a list of CPT's in the database, it's generated at runtime by PHP code. So instead, register your CPT's ...


2

I offer you an idea that I have already used something like this. I wanted to know the sites that my plugin uses, I created a cron job allow me to send me an email every week : add_action('init', function() { $time = wp_next_scheduled('dro_cron_hook'); wp_unschedule_event($time, 'dro_cron_hook'); if (!wp_next_scheduled('dro_cron_hook')) { ...


2

For attachment posts, the following should do it, i.e. use the wp_insert_attachment_data hook along with get_post(): function my_random_post_id( $data, $postarr ) { // Runs if the post is being created and not updated. if ( empty( $postarr['ID'] ) ) { // Locate a yet-unused ID in the (wp_)posts table. do { // Based on ...


2

That's not how filters work. Much like a filter in real life, something goes in, it gets changed, and the result goes out. Filters always take in a parameter and return something. They're an opportunity to change something So if we take this: $review_num_fetch = apply_filters('tourmaster_review_num_fetch', 5); This means the plugin uses 5, but it has given ...


2

It seems like your theme may be using the wp_is_mobile function incorrectly as it should not be used for theme specific styling, etc and is also unreliable as it only inspects the browser User-Agent. As I don't know what your theme is, I cannot say for definite if that is the case but see this answer for more information about that if you're interested. As ...


2

I've had this initial build that worked, even before the question. I've now seen @cjbj's answer as well as Mort's. Mort is on the same frequency, however, hear me out: Inside my main plugin A, which B will depend on, inside index.php: add_actions( 'plugins_loaded', function() { $boot = (new Init)->boot(); if( \is_wp_error( $boot ) ) { ...


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