5

I'm not aware of any other way but to use both add_action lines, for a single function. Example: function my_enqueue_sripts_function_name(){ // your enqueue logic here } add_action('wp_enqueue_scripts', 'my_enqueue_sripts_function_name' ); add_action('admin_enqueue_scripts', 'my_enqueue_sripts_function_name' ); There's no rule that forbids ...


5

Why WordPress creates two transients: Because the first transient with timeout in the name, is used for storing the expiration you set for your transient (but the stored value is a UNIX timestamp, not simply the value you passed like 3600) so that WordPress knows when to delete your transient. As for the second one, it stores the actual transient value that ...


4

Option 1 is the solution, here's a smaller example: $obj = new Obj(); .... register_block_type( 'my-plugin/my-block', [ 'editor_script' => 'editor-script-handle', 'render_callback' => [ $obj, 'block_save_function' ] ] ); In that code [ $obj, 'block_save_function' ] is equivalent to $obj->block_save_function(.... The ...


4

Actually, there are many ways to do what you asked, but I'm going to give you an example based on this example on the official React website, which uses AJAX with a class-based component (but there's also an example there using function component with hooks). So for the PHP part, we'll create a custom REST API endpoint and just for testing purposes, we're ...


3

The double NOT operator (!!) It's simply a way to convert/type-cast a non-boolean value to a boolean value, and !! <expression> gives us the opposite of ! <expression>. let foo = 'bar'; // non-empty string console.log( ! foo, !! foo ); // false, true foo = ''; // now it's an empty string console.log( ! foo, !! foo ); // true, false Issues in ...


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

WordPress taxonomy provides flexibilities to set its properties while registering it. To disable WordPress taxonomy archives, set "public" as "false" as shown in below example code. This will remove "View" action link from taxonomy screen and also redirect the user to website homepage when trying to access url of taxonomy ...


3

To add column to some WP table in DB, you could use $wpdb for it: global $wpdb; $table = $wpdb->prefix . 'my_table'; $sql = "ALTER TABLE `{$table}` ADD `new_column` VARCHAR(20) NULL DEFAULT NULL;"; $query_result = $wpdb->query( $sql ); $wpdb->query() returns false if your query went wrong, according to method's documentation. So ...


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

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

In the spirit of open source software, I would definitely start by contacting the original developer. If your changes are an improvement to the codebase, and do not take the functionality of the plugin in a new direction, collaboration may be welcomed. If your modifications are rejected by the original developer, there are some other things to consider ...


3

If you use a local dev environment you can run WordPress and your plugin on your computer, any changes you make are instant as there is no uploading/installation step. Since you are already using XAMPP, open the files directly with your editor from the XAMPP folder that contains the WordPress install. There is no need to upload and install as everything is ...


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

Use is_admin() function. It will return true if it's wp-admin page and false on frontend. more here https://developer.wordpress.org/reference/functions/is_admin/


3

There is indeed an unwanted ; (semicolon) in your function (try to look at line 99 in the twentytwentyone-child/functions.php file) which likely is the cause to the syntax error. So just remove that ; and the error would be gone: function my_service_template_footer_data() { echo "<script type='application/ld+json'> { '@context': 'https://...


2

Using wp_suspend_cache_addition( true ); at the beginning of the script solved the problem for me.


2

Add menus and submenus like: add_action('admin_menu', 'custom_plugin_menu'); function custom_plugin_menu() { $page_title = 'Parent Menu Title'; $menu_title = 'Parent Menu Title'; $capability = 'manage_options'; $menu_slug = 'parent_menu_slug'; $function = 'whatever_for_main_page_function'; $icon_url = 'dashicons-admin-generic'; $...


2

Actually starting since WordPress 5.6, there is such an API. Check out this blog post from November 2020 talking about the REST API Batch Framework.


2

You can also do it this way - plugin free. Open phpmyadmin, browse over to your wp_posts table and: SELECT * FROM `wp_posts` WHERE post_type="revision"; to see all the posts, their types and revisions and delete from `wp_posts` WHERE post_type="revision" Though afraid at first...I did it. And it worked without any impact to the site.


2

I wrote it myself using JS. It's just for one project and I didn't want to spend much time on it, so you have to adjust it for your personal needs ;) It hides chosen menu elements and creates a button which toggles them. You add it to the end of file /wp-admin/menu-header.php <script> // Here is list of classes of chosen menu elements you want to ...


2

to understand how to store choosen method id or else try using: // Make a shipping rate for each result foreach ($quote->shipping_options as $option) { $rate = array( 'id' => 'my_method_'.$option->id, 'label' => $methodNames[$option->name], 'cost' => $option->price, 'meta_data' => array(), ); ...


2

Your answer above was close but is should be add_action( 'upgrader_process_complete', 'wp_answ_355114' ); not do_action( 'upgrader_process_complete', 'wp_answ_355114' ); noting that this is only the case when a plugin is updated view WP plugin updates.


2

I'd put the dequeue statements inside the 'if', replacing the $loadscripts line. No need to set the flag and then check the flag to dequeue. That might simplify the code for further debugging. Edited: suggested code corrections: function contactform_dequeue_scripts() { if (is_singular()) { $post = get_post(); if (has_shortcode($post->...


2

its better to include your assets with admin_enqueue_scripts for your question add_action('admin_head', 'grup_custom_admin_post_css'); function grup_custom_admin_post_css() { $allow_post_types = array('custom_role', 'custom_role_2', 'etc'); $allow_roles = array('post_type', 'post_typ_2'); $current_user = wp_get_current_user(); if (...


2

There's no way to do this without a bit of programming. You need to look at these pieces: A Wordpress hook like save_post lets you do something when a post is saved or updated wp_mail is how you send an email get_field is how you look at the value of an ACF field. You'd need to write some code to put them together how you want to, but the details of doing ...


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

You can use two approach to prevent the user to click on your elem before complete the ajax fully. 1.Display loader and block that element so that no one can excute it until the ajax complete. 2.use a global var isAjaxProcess = false; now in your code make a condition block If(isAjaxProcess === false) { isAjaxProcess = true: Your ajax code goese here. And ...


2

I usually use CSS classes to control AJAX requests affecting a specific element. This way you can prevent unwanted AJAX requests on that element, while other AJAX requests may still be triggered, being bound to other elements. $('.slot').on('click', 'a.book', function(e) { e.preventDefault(); // Check if doing ajax if($(this).hasClass("...


2

Adding Markup To The Add New Site Form You can add HTML markup to that form like this: add_action( 'network_site_new_form', function() { ?> <p>Hello World</p> <?php } ); Adding Markup To The Edit Site Forms No. This cannot be done via PHP. For the site edit info screen, no hooks exist to do this. However,...


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


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