New answers tagged

0

I have already answered this question stackoverflow, but adding the answer here as well: Looking on the code it does not seem like the Wordpress way of doing this kind of thing. First you need to include your ajax-process.php in the plugins main file e.g: require_once plugin_dir_path(__FILE__) . '/ajax-process.php'; Second, you need to register your ajax ...


0

I found the way and here is the code how can we add colour picker in vc addon vc_map( array( "name" => __( "Product", "vc-addons" ), "base" => "sim-product", "class" => "", "category" => __( "Visual Composer Addons", "vc-addons"), "icon" => 'icon-sim-...


0

Try bellow Code: DB-Puller.php <?php /** * Plugin Name: DB-Puller * Plugin URI: https://my-web-site.com/ * Description: This is a my firt plugin, it(s allows to display data from database. * Version: 0.1 * Author: Firest Last name * Author URI: https://my-web-site.com/ * License: GPL3 */ function scripts_files_enqueue_scripts() { // ...


0

A form is not allowed to be a child element of a table, tbody or tr. Attempting to put one there will tend to cause the browser to move the form to it appears after the table (while leaving its contents — table rows, table cells, inputs, etc — behind). You can have an entire table inside a form. You can have a form inside a table cell. You ...


0

There is a simple and fonctionnal class on github to autoload with or without namespaces : Autoload classes in wordpress


0

I'd say generally you'd want to run as little code as possible right from your plugin file. It is way better to use hooks like muplugins_loaded or plugins_loaded, the later the better. This way code only runs after all plugins are initialized which means you don't need to worry about load order any more.


1

No idea why, but for the second snippet, changing the priority of the nested add_action from the default (10) to 20, causing the parent and child add_action to have a different priority solved the problem and now everything works perfectly: add_action( 'template_redirect', function() use ( $args ) { acau_enqueue_script ( $args ); }, 20); The reason ...


1

There's nothing technically wrong with this. It will work, but it's very important to make sure the usage of the filter is consistent everywhere it's used, otherwise you could experience issues. My suggestion would be to abstract the powers check into a separate function, and use the filter there. For example, the filter could be inside user_is_powerful(), ...


0

It depends entirely on the specific plugin and the specific hook. It's completely up to plugin developers what they want to allow other developers to do. They could allow developers to replace entire functions; to perform a custom action at the beginning, middle, or end of a function; to modify the result of a function; or none of the above. It's impossible ...


2

The code from core/columns and core/column blocks are a good example of how to achieve this behaviour. Basically we register 2 block types: Carousel and Slide. Slide block type does not appear in the inserter. Carousel block type is the root block which appears in the inserter. Instead of keeping the count of slides in an attribute we listen to getBlocks ...


0

Something like this... Creating slides elements const slides = []; for ( let i = 0; i < attributes.count; i ++ ) { slides.push( <li className="slide" key={'slide-' + i}> <img src='img-url.jpg'/> </li> ); } Adding slides to block content <ul classname="slides">{slides}</ul> You can use ...


0

Well, you also can use another and more elegant solution: register_activation_hook(__FILE__, function () { add_option('your_plugin_do_activation_redirect', true); }); add_action('admin_init', function () { if (get_option('your_plugin_do_activation_redirect', false)) { delete_option('your_plugin_do_activation_redirect'); exit( ...


0

add_action( 'add_meta_boxes', 'add_tmbu_address_meta_box' ); function add_tmbu_address_meta_box() { $screens = array( 'post', 'page' ); add_meta_box( 'your_fields_meta_box','Tmbu Address','show_tmbu_address_meta_box',$screens,'advanced','high' ); }


0

Thanks to https://salferrarello.com/functions-plugin-mu-plugin-wordpress/ I was able to confirm when Code Runs All of the code across the different files of WordPress can be thought of as one big list of instructions. The code is run line by line starting at the beginning of this list through to the end of this list. The order is essentially. ...


0

You have to create custom query, to get data from {$wpdb->prefix}postmeta depending on the meta_key and store the meta_values inside an array, then sum them. So we can build a function like this: /** * Query meta values by meta key. * * @return int Returns sum of meta values */ function get_meta_value_by_meta_key(){ global $wpdb; $metaValues =...


1

If you run wp_enqueue_script() inside a shortcode, which is essentially what you're doing by calling enqueueAllMyStuff(), the script is going to be queued up to be loaded in the footer. So if your shortcode runs a script as soon as it's printed, the JavaScript file that it depends on won't be available yet, and will cause this error. The simplest solution ...


0

Now, I believe wp_add_inline_script is maybe the better option. (https://developer.wordpress.org/reference/functions/wp_add_inline_script/)


0

I think your are missing parameters (even if you're not using those) as per its definition and always try to return into filters instead of echo the value. Try the following: add_filter( 'woocommerce_get_price_html', array( $this, 'get_price_html' ), 10, 2); public function get_price_html( $price_html, $product ) { return '<a href="my-price">' ...


0

I normally use plugins_url() method to achieve enqueue. function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', plugins_url('js/jquery.repeatable.js', __FILE__ ), '1.0.0', false ); } add_action('admin_enqueue_scripts', 'Zumper_widget_enqueue_script');


0

This is a good use case for either Transients or the Object Cache. The choice of which to use depends on whether you need to perform this query/check on every single request, or whether it only needs to be performed once every hour/day/week etc. For both options would would start by creating a separate function that performs the check and returns the number ...


3

You can use dangerouslysetinnerhtml, a special HTML attribute in React: dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from React, but you ...


1

I haven’t tested it, but you might want to try: element.createElement( 'div', null, {dangerouslySetInnerHTML: {__html: contentString}}, )


1

According to the WordPress Codex, using template_redirect to load a different template is discouraged and can cause certain code to not be executed, which of course can result in strange bugs. template_include is the more appropriate solution. It loads a template file but without the behavior mentioned above. add_action( 'template_include', function($...


1

According to https://github.com/radekzz/wordpress-react-in-theme, you can just include script as Babel type, not JavaScript if you don't want to use webpack to print JSX. But in this case your code will not be compiled.


1

There's nothing wrong with using the global $post variable per se, although there are people who will say that using global variables is always bad. But since you're using it multiple times in the same object, it would be better to just get the post once and store it in a class property. I prefer using the WordPress get_post() function because it looks ...


1

The error is self explanatory: PLUGIN_PATH is not defined anywhere. It is not one of WordPress' default constants (which are listed here, and all start with WP_). In the context of the code you've copied, it's apparent that it was either supposed to be replaced with the path to your plugin (in which case using a constant in the example code was a bad idea),...


1

The issue here is not about getting the value — $settings['download_file'] (in PHP) would give you that value, if any. What you're really looking for, is to make Elementor aware of the file input changes, so that the new value will be saved by Elementor. And the trick is, trigger the input event on the file input after the file has been successfully ...


3

The data passed by wp_localize_script() is output in a <script> tag in the page HTML. So if you have this: wp_localize_script( 'registered_script', 'serverData', array( 'posts' => $post_array ) ); This will be on the page: <script type="text/javascript"> /* <![CDATA[ */ var serverData = { "posts": [] }; /* ]]> */ </...


0

I think the best way to approach this is by creating 2 blocks with a parent -> child relationship. The child block would be a nested block only available within its parent block. Note the parent defined below. registerBlockType( 'prefix/childblock', { title: __( 'Inner Child Block' ), parent: ['prefix/parentblock'], attributes:{ ...//the rest of your ...


0

The problem is that $user_id = bbp_get_topic_author_id( $topic_id = 0 ) is malformed. You need to remove the = 0 from $topic_id = 0 and make sure that the variable $topic_id actually contains the ID of the topic you are trying to get the author of.


1

It is possible with MySQL, and it doesn't seem to create any problem with wordpress's dbDelta() Here is the line you need to change $charset_collate = $wpdb->get_charset_collate() . ' engine = innoDB'; You simply have to add engine = innoDB at the end of the SQL query and the correct engine will be used by MySQL


0

Alright, I came across another answer that's finally solved this. I had a function (in functions.php) which revoked admin access to some user types I'd created with custom privileges - that was blocking non-admin access to admin-ajax.php. Old/new function below: Old function // Revoke dashboard access add_action('admin_init', 'restrict_access_admin_panel');...


1

Any rule that doesn't point to index.php is interpreted as an external rule and gets added to .htaccess. $matches array works only when second argument ($redirect) of add_rewrite_rule() point to file index.php. External rules need to use the $1, $2 instead of $matches[1], $matches[2]. Remember to flush rewrite rules after the change.


0

Here is the solution: register_activation_hook( __FILE__, 'rest_api_hook' ); /** * Runs only when the plugin is activated. */ function rest_api_hook() { /* Create data */ set_transient( 'rest_api', true, 5 ); } /* Add notice */ add_action( 'admin_notices', 'rest_api_hook_exec' ); /** * Rest API Notice on Activation. */ function ...


1

The syntax should be: add_action('update_option', [$this, 'update'], 10, 3) because your function is accepting 3 arguments: public function __construct() { add_action('update_option', [$this, 'update'], 10, 3); } PS: add_action()'s reference.


0

Since it is working on your local machine and not on the server, I suspect that it is environment related. This causes me to suspect: $archive_template = dirname( __FILE__ ) . '\partials\archive-plist.php'; If you are running this on a standard LAMP stack, it is likely that you should be using forward slashes (/) instead of backslashes (\). Also, there is ...


0

I solved the my issue. this code may help others in future. // Display a custom checkout field add_action( 'woocommerce_checkout_before_terms_and_conditions', 'custom_checkbox_checkout_field' ); function custom_checkbox_checkout_field() { $value = WC()->session->get('add_a_product'); ...


-1

If you are wanting to provide a mechanism for plugin updates anyway, you could setup your own plugin update server like Plugin Update Checker. This way you could add some kind of logging function to the update server to record the URLs calling it when checking for updates.


-1

If you don't distribute through the WP repository, but from your personal site, then I assume you have some process to track sales. You could build into your code a "URL code" that is keyed to the buyer's URL (which you collect during the sales). That key would check the URL of the site it is running in, and block it running if the URL doesn't match the '...


1

You did some mistakes that I have described below: First thing you have placed jQuery Ajax code on the wrong place. On ajax callback function variable name mashup like $post_id defined and used on update time $post_ID; PHP is case sensitive so it considers 2 different variables. In some places, not closed } brackets. Here is the right code which I have ...


0

I had a similar problem to the one you have described. In the end i had to hook into woocommerce_subscription_status_active from which you can access the related $subscription object as a single argument. If you need any further details from the standard $order object also then you can access that via $subscription->get_parent() within your function. The ...


Top 50 recent answers are included