New answers tagged

1

In the context of official plugin repository this is very explicitly forbidden by the guidelines (emphasis mine): 7. No "phoning home" without user's informed consent. This seemingly simple rule actually covers several different aspects: No unauthorized collection of user data. For example, sending the admin's email address back to your own ...


0

You need to hook your function to delete_attachement hook, but you also need to remove some extra functions that are called before calling your hooked action to reach the right caller of wp_delete_attachment(). Here's a possible implementation... function my_backtrace( $post_id ) { $bt = debug_backtrace(); array_shift( $bt ); // Remove ...


3

From what you are saying you have translated your plugin and now you want to be sure the future update won' be overwritten. So to avoid that happening you can always put your po/mo translation files (if provided) in global languages folder that is located on your server in wp-content/languages/plugins folder. If plugin have language file name for example ...


0

You're almost there I think, I'm trying the same thing and came across your post! $url = wc_memberships_get_members_area_url($active_memberships[0]->get_plan_id(), 'my-membership-content' ); You have to pass the section as the 2nd argument as there is a bug in the WC code which throws an error if not. This also assumes you are picking up the first plan ...


0

It depends what you want to do. If you look into the function definition, you'll notice some do_action(): For example: do_action( 'delete_attachment', $post_id ); do_action( 'delete_post', $post_id ); do_action( 'deleted_post', $post_id ); These are points, called hooks in WordPress, where you can actually run your stuff. Hooks will help you to modify ...


0

Welcome to Stack exchange :) Some other plugin ( or your plugin elsewhere ) may be getting executed later, and maybe adding some elements to the array. Try to give your hook a higher priority, replacing your tweak method with following... function tweak() { foreach( $this->get_post_types('objects') as $type => $data) { ...


1

This is probably the root cause - https://core.trac.wordpress.org/changeset/36510. Core have moved from saving menus in $_POST to sending them as json encoded and then decode it into $_POST. I am not very familiar with how menus are sent to the server, but you probably either use the wrong hook, use the right hook but too early, or there is a bug in core.


3

Did you try just using option.php? <form method="post" action="options.php">


0

You need to have a <form> element. By not specifying a form action attribute the form posts to the same page you are on which makes this easy to process. Also an id on the textarea is not enough you need to add a name attribute to catch with $_POST for processing. Also adding a nonce field is good practice, and checking permissions to be safe. Try ...


1

Your shortcode should look something like that function se224467_shotcode_star_rating( $atts ) { $a = shortcode_atts( array( 'grade' => 5, ), $atts ); $full_stars = floor( $a['grade'] ); // full stars $output = str_repeat( '<i class="fa fa-star"></i>', $full_stars ); // if not a whole number append a halt ...


0

I think you are looking for this- function star_rating( $atts ) { $max = 5; $atts = shortcode_atts( array( 'grade' => $max, // default ), $atts ); $star_icons = ''; $full_star = floor( $atts['grade'] ); for( $i=1; $i<=$full_star; $i++ ) { $star_icons .= '<i class="fa fa-star"></i>'; } $half_star = 0; if( (int) ...


1

The comments_array filter as part of the comments_template() function, the purpose of which is to load a comment template. It filters comments being prepared to be rendered in the comment section of singular type pages. The preprocess_comment and comment_post actions (in that order) both fire as part of the wp_new_comment() function, the purpose of which is ...


0

The answers here are overthought and too complex. Why deactivating the plugin instead of preventing activation? Something as simple as calling die('your error message here) upon activation will do the job. function activate($networkwide) { if (is_multisite() && $networkwide) die('This plugin can\'t be activated networkwide'); } ...


1

Ok i've found the solution. In fact, as i haven't noticed, there is always the hashed mdp, but for now, the logged_in cookie is structured like this : %login%|%timeout%|%sessionId%|%passhached% instead of : %login%|%timeout%|%passhached% This is like this since wordpress 4.0, and the wp_session_cookie integration, the auth method is the same that before ...


1

Not allow. Your user is not a software developer, pretending that he is can only end bad. This is even before speaking about security etc. If you think that there are callbacks that make sense, just provide them yourself.


1

Never let anyone add any jQuery scripts via any text editor. How are you going to know if the script is malicious or not, how are you going to handle jQuery errors, how are you going to know if the jQuery is even proper and allowed jQuery. eval() brings an added extra security risk and should be avoided where user submitted strings are to be evaluated. ...


0

The best way to sort it is contacting: plugins@wordpress.org I'm not sure that they'll change the url though. Regarding name of the plugin, simply change it through the php file header and also from the readme.txt file of your plugin.


1

You can change the name of your plugin, you just can't change the url slug of your plugin. Meaning, if you initially added a plugin to the repo and it was called "Posts With Ad Thumbnails" your url would be: https://wordpress.org/plugins/posts-with-ad-thumbnails/ After uploading your plugin, if you decide to change the name just edit your primary plugin ...


1

$all_the_images = get_attached_media( 'image', 31 ); should return any image attachments for a page the ID of 31 if that page has child images. Meaning, there are images that were uploaded and actually attached to that page, not just upload and inserted into that page. When you use the media uploader (to upload images), from within the Edit screen of the ...


3

When looking at either The Codex or Code Reference there's usually a little snippet at the bottom which says: Since: WordPress x.x.x If we take a look at wp_enqueue_script() for example we see toward the bottom above the contributor notes that it has been around: Since: WordPress 2.1.0 Now we can use the WordPress Release Chart to find out when ...


1

wp_enqueue_script is since Wordpress 2.1.0 https://developer.wordpress.org/reference/functions/wp_enqueue_script/ wp_enqueue_style is since Wordpress 2.6.0 https://developer.wordpress.org/reference/functions/wp_enqueue_style/ Found via a quick google


3

No, outside of purely technical aspects of PHP includes (as you correctly pointed out), there is no additional overhead to plugin quantity on general WordPress core load.. The list of active plugins is calculated in advance and stored persistently. The load process just runs over it and performs PHP includes on each. The edge cases where it does take ...


1

Try this: <input type='file' name='adm_uploads[]' multiple />


1

It's should be return rather than echo. return '<meta name="site_title" content="'.'test test'.'">'."\n";


3

Since the logic used for updates from official repositories is both fuzzy and exact details are kept secret — it's not possible to reliably dodge it by merely manipulating details. The only reliably practice at the moment is to filter out data from the set sent for update check. Even that is highly inconvenient and needs to be performed on HTTP API request ...


0

My customer wanted "free shipping" over orders 100 < so I used a custom woocommerce/cart/cart-shipping.php Take a look at the contents of it, might help you: https://gist.github.com/eminozlem/ab93b3d91413e59eb86e8601c418656d


2

WordPress registers jQuery in the wp_default_scripts() function, which is found in wp-includes/script-loader.php. // jQuery $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.11.3' ); $scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.11.3' ); $scripts->add( 'jquery-migrate', ...


0

I managed to do it by myself thanks to this tutorial. Moved content of do.php file to a function named cmr_upload inside a class. Then changed the plupload options from: url : plugin_dir + 'do.php', ... multipart_params : { "chapter_id": i, "path": path to url : '<?php echo ...


2

depends if you want to write OOP or just use PHP classes ;) wordpress hook system is procedural in nature and there is a big amount of globals being used so it takes some mental effort to translate it into actual OOP. Most (99.9%) people attempting this fail and produce something which is basically procedural code wrapped in a class. TL;Dr You can use ...


1

Off the top of my head I can't think of any instance where you would want the WordPress admin to be the main entry point for your website, that there isn't a more suitable software to use. Do you have a specific application or use in mind? In general I would say say, yes it is best practice to keep the admin potion of your WordPress install for ...


0

Add a security object for file uploads like so: class FileSecure { public resource $Allowed; private object $Info; public function __construct($allow) { $this->Allowed = $allow; $this->Info = new finfo(); } public function Check($file) : bool { if(in_array($fileType = ...


0

You need to add a condition: function my_editor_content( $content ) { $content = ""; if ( 'movie_reviews' == get_post_type() ) { $content = "This is some custom content I'm adding to the post editor because I hate re-typing it."; } return $content;


1

There is no action variable on the data you're passing to Ajax. This way WordPress is sending just a generic call to Ajax which always return 0. You must edit your data on your JS file to something like: data: { 'user_input': user_input_last, 'action': 'tags_autofill_function' },


-1

You can simply use wp_enqueue_script or wp_enqueue_style in the widget method (function) in your custom Widget class and it will load the scripts only if the widget is active. See details and example here: https://wpshed.com/wordpress/load-scripts-styles-widget-active/


0

I'm beginner in jQuery AJAX too, and I always tried with $.ajax, but I'm using just $.post to my requisitions now and they work well. The syntax is more simple and less risk to make a mistake. Obviously, if I'm wrong in this way, please someone alert me about it. In $.post() you need to put the url, the variable would get by POST as object and a handler ...


0

According to Function Reference for wp_list_comments, you can set the arg Echo to false to return the list. I imagine the default walker will not echo the code if this is set to false. wp_list_comments(array('reverse_top_level' => false, 'echo' => false), $comments);


1

I see two things. You're missing an action call - you need add_action( 'wp_ajax_render_admin_charts_page', 'render_admin_charts_page' ); add_action('wp_ajax_nopriv_render_admin_charts_page', 'render_admin_charts_page'); Plus, from looking at your render_admin_charts_page() you need to change your json dataType to html. Your charts function is outputting ...


1

Part 1: Form Handling Firstly, lets fix your upload form handling. You should never send the user to a dedicated PHP file for processing, wether it's a form or an upload because: The file then has to bootstrap WordPress to use the WP API, tightly coupling it to your folder structure, and introducing fragility The file will work even if the plugin has been ...


0

This requires a definition of what is "auto update", but in the most general sense, a plugin can do whatever any other part of wordpress can do therefor a plugin can trigger an auto update without human intervention. On the more practical side, this is very unlikely, and hiding the indication should be good enough for all practical usage. Still hiding ...


2

Wordpress will work with PHP 5.2.4+ and MySQL 5.0+ but the Wordpress docs suggest sites run on 5.6 or greater (April 6, 2016). For personal themes/plugins I would suggest supporting at least php 5.5, but for plugins/themes you are trying to sell you may want to go down to 5.3. While PHP versions 5.5 is nearing end of life and 5.4 and below are no longer ...


1

I recommend you these videos --> https://www.youtube.com/playlist?list=PLIjMj0-5C8TJYSkKnUyHH1VXlIpvZXOMT In my opinion I prefer use the plugin ACF. The plugin helps to save time. It's easy to use and the client will be happy. Also, the client won't care if you used a plugin or you wrote the code by yourself, the client will care if the functionality works. ...


0

You have two problems in your code. You use $post as a iteration variable which is an habit best avoided You use setuppostdata which changes the global $post without you using any function that actually needs it your loop should look like foreach ( $pp_query as $p) : $pointer_query[] = array( 'id' => get_post_meta($p->ID, ...


0

plugin_basename may be what you want. If your plugin file is located at /wp-content/plugins/my-plugin/my-plugin.php this would return: $file = plugin_basename( __FILE__ ); // "my-plugin/my-plugin.php" If you called the same thing from a sub-directory in your plugin, such as /wp-content/plugins/my-plugin/inc/my-plugin-include.php it would return: ...


0

I think using plugin_dir_url solves this efficiently: $url = plugin_dir_url(__FILE__); $imageurl = $url.'images/wordpress.png'l


1

I think you are looking for plugin_dir_url: $url = plugin_dir_url(__FILE__); $imageurl = $url.'images/someimage.png'; EDIT: Sorry I misread the question... that is only an answer to the linked question. You could check the parent directory recursively until you find the right one: function base_plugin_dir($dirpath) { if (substr(dirname($dir),-7) == ...


0

Edit My bad, in that case I can think of this. $x = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); It should return http://[url-path-to-plugins]/[custom-plugin]/ But straight forward class I don't think wordpress has one Yes it is from https://codex.wordpress.org/Function_Reference/plugin_basename $x = ...


0

Whether a post is a draft or published is defined by the post status, not any of the meta fields, so you'll have to hook into wp_insert_post_data and force the post_status to draft if anything in your form is invalid: add_filter( 'wp_insert_post_data', function( $data ) { if ( $data['post_type'] != 'zip_code' ) return $data; // Validate ...


2

Add a post meta field to indicate this post is just a redirect when creating it: $postid = wp_insert_post($newpost); add_post_meta($postid,'redirect','1'); Check the post meta value and if it is a "redirect post", just output the post content (javascript redirect): add_action('wp','custom_maybe_redirect'); function custom_maybe_redirect(); global ...


0

I have worked on your issue and found a solution after some Google. Note: Add the below mentioned code to theme's functions.php or any plugin's file. Code: This filter function will add a custom tab to the Products Data metabox <?php add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 ); function ...


1

I figured out what was causing this, but it was by trial and error since there was no good debug info. And the error was in the main (custom post calling) part of my plugin, NOT in the options as I had surmised earlier. I ended up finding out that I needed to be using 'content' => $p->post_content in my query/foreach loop in place of 'content' ...



Top 50 recent answers are included