New answers tagged

1

According to the developers handbook, these are the functions that should be used when outputting anything: esc_attr() // Use on everything else that’s printed into an HTML element’s attribute. esc_html() // Use anytime an HTML element encloses a section of data being displayed. esc_js() // Use for inline Javascript. esc_textarea() // Use this to encode text ...


-1

You could do if( function_exists('mepr_process_login_redirect_url_fn') ) { add_filter() and some_mb_function go in here }


0

Here's how I do this: // if admin send them to the dashboard, otherwise leave them on the frontend add_action('wp_login', 'rt_login_redirect', 10, 2); //use this action if you want them to be redirected only after login but leave the ability to to to the dashboard later (ie changing profile or pw). add_action( 'admin_init', 'rt_login_redirect' ); // use ...


0

If you want to flush_rewrite_rules when ANY plugin is activated or deactivated add_action('init', function(){ // Get the path of every plugin installed $pluginsInstalledPaths = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); foreach ($pluginsInstalledPaths as $pluginPath) { // Get all PHP files available in the plugin root directory $...


1

There is to filters needed for optimizing all images, that will be uploaded: add_filter('wp_handle_upload', 'random_function', 10, 2); add_filter('image_make_intermediate_size', 'rand_function2', 10, 1); function random_function($array, $string) { // Some random action with main image return $array } function rand_function2($file) { // Some random action ...


0

Although @SallyCJ's answer might work, and is probably good information, I went in a different direction that worked for my application. My application needs a hidden field in the comment form. Although you can easily add the hidden field to the front-end comment form, the back-end doesn't use that process. But my application needs the POST of that hidden ...


1

Hook add_attachment fires before images cropped via wp_ajax_crop_image(). That's why Wordpress trying to work with files, that is not existed for now.


0

Because the main menu has manage_options but the sub menu has manage-options, it should be _ not -. Since nobody has the manage-options capability nobody can see that submenu page.


1

There's zero meaningful difference in performance between plugins and functions.php. All plugins are is PHP files that WordPress will run as it loads, and functions.php is just a file in the theme that WordPress run as as it loads. Performance is not a consideration when choosing between a plugin and functions. The right choice depends entirely on what the ...


1

If you check the source code for $wpdb->update() the very last thing it does is prepare the query and then run it and return it. So to answer your question, it is safe and the documentation is correct.


1

Generally you do not want to access your PHP files directly within WordPress because you lose a lot of "juice", meaning all WP functionality would have to be re-imported (and might break). WP is setup in a way that all requests to the CMS get routed to index.php and some mechanisms then decide what to do with the request. From what you write, it ...


1

Is there a filter for the adding of fields to the comment box form that is on the admin/comments page? If you meant the inline form for editing or replying to a comment at wp-admin/edit-comments.php, then, The form is outputted using wp_comment_reply() which has a hook with the same name, i.e. wp_comment_reply, and you could use that to return your own ...


0

Welcome to WordPress and WPSE! Plugins are meant to alter or add functionality to what is already provided by WordPress Core. They are not meant to be accessed directly. So for example, a plugin might add links to the most recent posts on your site, to the end of every post. It sounds like the best path forward for you is to learn more about how WordPress ...


0

When you look at the bootstrap documentation for the version you want to use, you will find that the markup of the modal has slightly changed. (https://getbootstrap.com/docs/5.1/components/modal/) The data attributes have now an added -bs- in them.


0

add_action add_action currently supports 4 parameters: string $hook_name, callable $callback, int $priority = 10, int $accepted_args = 1 Try adjusting the 3rd parameter "priority" to add the action later than any existing actions (which may have been created by plugins or themes).


2

You would implement this: https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/ First you would add a Update URI: header to your plugin with a custom domain. Second, you would add a filter to your plugin, using the filter name update_plugins_{$hostname} where {$hostname} is the value you gave your Update URI: . E....


1

You probably wouldn't. If you did it would be to make sure it was in place already if in future you decided to make the variable dynamic or filterable. In this case I would suggest it for similar reasons to #1. You may know where $class is coming from now, but this may change in future, and it prepares the function for potential use in different contexts ...


0

I think the best answer is in the official doc: https://developer.wordpress.org/plugins/security/securing-output/


0

The issue with your updated code is that because you are using add_rewrite_rule() inside the filter, it can't properly add it to the top of the list. You can see this if you dump out the $rules array. Because it gets added to the end of the $rules list, WP steps in beforehand to match on slug alone using some magic in the background. In order to circumvent ...


4

You can/should prefix all your classes. That way you have very limited chance to have conflicting classes, which can cause unexpected behaviour on the front-end. So, instead of .container, you can use .mypluginprefix_container.


0

Support for plugins that do not reside on wordpress.org appears to be supported by wp plugin install and MAY also be supported by wp plugin update. Daniel addresses a syntax issue with that feature here: https://github.com/wp-cli/wp-cli/issues/2170 Documentation for install indicates acceptance of a plugin slug (.org) or the path/URL to the ZIP file: https:/...


0

How to show the post which checkbox is not selected? I don't know what the meta value is set to when the checkbox is not checked (or maybe no meta set at all?), but you can use the meta_query argument for searching for posts where the meta is not set (not yet added to the post) or that the value is empty, e.g. in your case, "empty" could mean the ...


0

Try applying these and your code might work: Looking at the expressions $type_of_running == 'manually_run' and $type_of_running == 'planned_run', where you're expecting get_post_meta() to return a single meta value, you should then set the 3rd parameter to true: // Set the 3rd param to true to get a single meta value. $type_of_running = get_post_meta($...


0

So i finally figured it out, the gallery switches modes sometimes, even without clicking anything (not completely sure what actually happens, I have no idea about Backbone tbh.) Here is what now works for me: if(wp.media.frame.content.get('gallery').collection) { wp.media.frame.content.get('gallery').collection.add(formatted); } else { wp.media.frame....


3

The curl is sending a POST request, to convert this you'll want to use wp_remote_post(). As described in the documentation, the request arguments are the same as WP_Http::request(), so let's look there how we can replicate your current version. curl_setopt( $ch, CURLOPT_URL, $url ); just sets the URL. Already doing this with wp_remote_post() curl_setopt( $...


0

That's not really a question, but as a not really an aswer, here are a few guidelines that you should keep in mind. Code convention Always try to prefix your functions with something unique (ex. your company name). This will be used like a namespace to avoid function name collision. Database Creating and updating a custom database table should be done in the ...


0

I think it's a bit tricky but using https://developer.wordpress.org/reference/hooks/plugin_loaded/ to know if the plugin has just been activated. I think check if a plugin is added to get_option('active_plugins'); And doing your stuff when you detect something new


3

So I presumed your sub plugin loads after the main one, right? Here i can see that new value is added to array but now i have to define test2 function inside my sub plugin If you're certain test2 successfully added to the array and that test2 was being called from MyClass::autoload_function(), then you can try using an early hook like init to define test2, ...


0

It depends where you want to apply your custom css class. CSS class for table row If you want to add the custom class to the <tr> element, I recommend to overwrite the function single_row like so: public function single_row( $item ) { $cssClass = ($item['view_status '] == 1) ? 'make-it-green' : 'make-it-grey'; echo '<tr class="'.$...


1

Looking at your if-else block, I see there's a $post_id variable, so if it's the ID of the post that you want to assign to the user you're creating, then you could just call wp_update_post() in your else block, i.e. right after you create the user. So just replace the wp_insert_user($userdata); in your code with this: $user_id = wp_insert_user($userdata); ...


0

Issue got solved by doing two things Removed primary calling from /** * Initialize the activation works of the plugin. */ function awraq_activate_plugin() { //removed } register_activation_hook(__FILE__, 'awraq_activate_plugin'); Added the call to "plugins_loaded" /** * Initialize the plugin. */ function awraq_init_plugin() { if (...


0

First off, you need to fix the comment_meta value. It should be an array of meta key and value pairs, and not just the meta value. So give the meta a key (or name), e.g. message_id, and then do something like so: 'comment_meta' => array( 'message_id' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true)), ), Now to check ...


3

WordPress does not serve those files, when you request a PDF it's Apache/Nginx that serves the file to the browser, no PHP is executed. This is a good thing as it's much faster than PHP and saves a lot of server resources. For this reason, your attempt won't work, and no changes to the PHP will fix it. I want to be able to know how often a user is accessing ...


0

Do you actually insert the comments right after you created the CPT post? I.e. Both the snippets in the question are in the same scope, e.g. wp_insert_post( $post_array ); for($j = 1; $j <= $total; $j++){ ... wp_insert_comment($comment_array); ... }. If yes, then you can store the post ID returned by wp_insert_post() to a variable and then just use that ...


0

I maybe misunderstood, but you can create your comment thanks to https://developer.wordpress.org/reference/functions/wp_insert_comment/ which will return you the comment_id on success. In the parameters you can pass the post_id of the original mail in comment_post_ID


0

You can store values in a database and get that value from the database and pass the value to shortcode from the database. Now you just need one admin page to update these 4 values. to add menu page refer this for example, after creating page you can save this 4 values in side option table using update_option() and using get_option() when needed. ...


Top 50 recent answers are included