Tag Info

New answers tagged

0

You need to use functions like add_action() or add_filter(). Suppose you want to add a plugin's functionality after the content of each blog post, use: add_action( 'the_content', 'plugins_function_name' );


0

function optionExists($option_name) { global $wpdb; $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option_name)); if (is_object($row)) { return true; } return false; }


0

Consider using posts (or an alternative custom post type: portfolio, products, etc...) to manage all your content. Check out the thumbnail stuff. Basically, you will add an image to each post via the wp-admin Posts manager to a field called 'thumbnail'. Then you can use the built in thumbnail functions from within the loop mechanism to do cool stuff. ...


0

WP MVC (an MVC framework for WordPress) is the best plugin. We are using it now, maybe it will suit your needs.


2

Your problem is that you're using Reserved Terms. error is a reserved term, you can't use it. To get around this, you could intercept the request early, and do a redirect, changing the query parameters in the process. For example, handling a link get parameter: add_action( 'wp' , 'reserved_term_intercept' ); function reserved_term_intercept(){ global ...


0

Try using remove_menu_page(). https://codex.wordpress.org/Function_Reference/remove_menu_page


0

I have no idea if WP API has limits, but, you should always cache your requests every time you deal with a third party API access. it is a good practice to cache the response for an hour or whatever, it will help optimizing the site which will use your plugin, thus it loads faster due to cached responses. I suggest you use Transients API « WordPress Codex


0

I just had to clean buffer and then do my stuffs and call exit ob_clean(); //clear buffer header('Content-type: text/xml'); header('Content-Disposition: attachment; filename="text.xml"'); echo $xml->asXML(); exit(); Thanks to they guys here for solution!


0

This really depends on the scoping of the code you want to use and whether there are actions or filters that encompass the functionality. You should be able to check whether the code you want is available with a combination of class_exists() and function_exists() calls. But this will depend on whether the classes and functions you want to use are scoped as ...


2

I found a way to get it done but I am not very happy with this procedure. Please add your answer if you find better way. Mean while, this might be of help. add_action('admin_head-edit.php','addCustomImportButton')); I only need this on edit page, so I am using admin_head-edit.php action, but you can use admin_head or some other (not very specific ...


1

You are almost close. add_filter( 'some_custom_filter', array( $this, 'filter_suppress_the_content' ), 10, 3 ); // the above line states that, the method `filter_suppress_the_content` should have three arguments, where you have used nothing. public function filter_suppress_the_content() { return true; } // comparing your code, this method should have ...


0

Sitting with the same "problem". At first i was thinking of store this cache as an option, but my cache simply was too big so this did not work. So maybe that's an alternative if your cache never will be really large. For example if you're communicating with an API and can only do a few requests per hour and that the return answer is not too long. :)


0

MY found SOLUTION WAS: global $wp_rewrite; $wp_rewrite->flush_rules(); $wp_rewrite->init();


5

Both approaches are not mutually exclusive. As @gmazzap said, don’t create a callback hell. But you can provide an initial hook, so other developers don’t have to rely on the rather slow function_exists() checks. Example In your plugin, provide a hook that other developers can use to call your classes and functions safely. add_action( 'wp_loaded', [new ...


4

Surely this approach has some benefits, but has also some issues. It's not really easy to use If the target of your plugin are WordPress developers, they will be very familiar with plugin API, but end users are not. For a non-developer, something like: $data = give_me_the_data(); It's easier to understand, remember and type than: $data = ...


1

Would you please try below code to your plugin page. if the script file is your plugin root directory. function plugin_adding_scripts() { wp_register_script('my_test_script', plugins_url('testscript.js', __FILE__), array('jquery'),'1.1', true); wp_enqueue_script('my_test_script'); } add_action( 'wp_enqueue_scripts', 'plugin_adding_scripts' );


1

I would use the add_rewrite_rule() function, please note that the code is untested but it should work depending on your specific use. If you also need to set a post_id, just add it to the index.php?p=X... string. function myplugin_filter_add_rewrite_rules() { // Allow for /myplugin/filter/someFilter add_rewrite_rule('myplugin/filter/([^/]+)/?$', ...


1

Use wp-admin/admin.php with an action parameter: <a href="<?php echo esc_url( admin_url( "admin.php?action=wpse_184153_create_page&user_id=$user_id" ) ) ?>">Create Page</a> And then hook onto the event: function wpse_184153_create_page() { $redirect = admin_url( 'users.php' ); if ( ! empty( $_GET['user_id'] ) && ...


-1

You may always need to check initation for the class to be called which seems to be your problem. In your case you can always simply call the class when included like below: $csvImporter = new CsvImporter($parse_header, $delimiter, $length); Or if you adding the class into the WordPress init hook such as a plugin format. add_action('init', array($this, ...


2

First, you have to initiate the class, something like: add_action( 'init', function() { $CsvImporter = new CsvImporter; } ); Also, you are using extract() wrong; extract() won't build $attributes as an array. Anyway, extract() is not recommended any more and you should avoid using it. Also, note taht if ($attributes['mods']) should be if ...


0

The 'init' action runs everytime WP loads. You should be using 'register_activation_hook' for the functions that you want to run on plugin activation. register_activation_hook( __FILE__, 'insert_page' ); function insert_page(){ // Create post object $my_post = array( 'post_title' => 'My post', 'post_content' => 'This is my ...


0

All the answers you see here are correct enough, but here's what probably (probably!) really matters: If your multiple plug-ins use code redundantly, they'll be worse, performance-wise, than one plug in with all the functions and doesn't repeat itself. This is actually WordPress'argument for "why Jetpack isn't a resource hog"; they wrote really clean ...


3

This approach should work for you: <?php /** * Plugin Name: Rewrite Shortcode **/ add_shortcode( 'myplugin', 'mp_shortcode' ); function mp_shortcode(){ return '<p>Filter: ' . get_query_var( 'filter' ) . '</p>'; } add_action( 'init', 'mp_rewrite' ); function mp_rewrite(){ $post_id = 2; add_rewrite_rule( ...


0

Have you looked at this? puphpet If appears to help you create config files. Looks like you can set up multiple vhosts and have it execute custom commands post-init. So you could have it set up all the folders, hosts and databases and then copy your desired versions over with associated wp-config files? A little bit of set up initially, but might work. I ...


3

I would be wary of things you read - e.g. there's a common myth that "having lots of plugins" is a bad thing, whereas of course what matters is whether they're well written or not. The time to load a large number of very well written plugins is neglible, whereas a line of bad code in one can easily screw things up for everything else. There might be a case ...


5

Having two or twenty plugins does not make difference because of the number of plugins itself. Maybe you can notice difference from one plugin to 1000 thousand, but not from 2 to 20. What the plugins do is what makes difference. Having 50 light plugins can be fast, while having one single plugin doing a heavy job or really poorly coded can be quite slow. ...


0

The wp_get_archives function in Wordpress does not support displaying dates. However my solution worked without using this function it's still probably handy for your or someone else his cause: In the functions.php file of your theme place the following: function recentPostsDate() { $rPosts = new WP_Query(); $rPosts->query('showposts=6'); ...


1

Don't even start. Ignoring official API is a no go, at best it will just creat headache for you and nasty surprise for the users when the plugin will fail when pinterest changes something and since it forces you to..... store user and password in a very unsecure way. This might be ok if your pugin is aimed to be run only for admins of non network wordpress ...


1

You can override the author link via the author_link filter: function wpd_author_link( $link, $author_id, $author_nicename ){ return 'http://my.blog.tld/'; } add_filter( 'author_link', 'wpd_author_link', 20, 3 ); $author_id and $author_nicename are available to the filter so you can fetch whatever data you need to generate the correct link.


0

I was able to find a solution: if(!empty($search)){ $query = $wpdb->prepare( "SELECT DISTINCT user_id FROM wp_usermeta WHERE meta_key = 'pie_address_3' AND meta_value LIKE %s ", '%' . $search . '%' ); $ids = $wpdb->get_results($query); ?> ...


0

When I seemingly get nothing from an Ajax call I run Fiddler and examine the return when it comes to the request. The other day an Ajax call was failing inexplicably. Upon examining the return I saw another programmer was dumping an array into the output before I received my response. I never would have guessed that because the JavaScript never hit the ...


1

Your problem is probably because you do not return a json object but an html (actually mixed text and html), and you set jQuery to validate that the response is json, which it isn't. your code at the ajax handler should be something like $catshtml = wp_dropdown_categories(.....echo=0); $ret = array('data' => $catshtml); wp_send_json($ret); die(); on ...


0

That's expected behaviour, since you're calling wp_enqueue_script mid-page, so at that point the <head> ship has sailed, and the only other option is to enqueue in the footer, which is fine. I didn't spend too much time reading the actual script that you're enqueuing, but it seems like it it's doing some document.write() as soon as it's loaded, which ...


2

Filters should return, not echo. function my_content( $content ) { // Something something $content = 'my content'; return $content; } add_filter( 'the_content', 'my_content' ); You can echo, but you'll need output buffering, like this: function my_content( $content ) { // Something something ob_start(); echo 'my content'; ...


1

You should hook save_post instead of publish_post. publish_post only runs when a post is initially published and won't catch subsequent saves. Additionally, the publish_post hook passes parameters to your function and those should be used to retrieve info about the post being published rather get_the_content(), which only works when you're inside the ...


0

The author key/value query won't work. Try modifying the query by moving the query out of the meta query like so: array( 'author' => $author, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'leads_status', 'value' => '-1', ), array( 'key' => ...


0

1) Please remove extra spacing in the inner pages or plugin pages. 2) remove the inline styling in the pages or plugin pages. its worked for me everytime. i have used many times same method. when the problem error in the plugin page or Wordpress page. Regards, Hitesh Nagpal


0

As @s_ha_dum has correctly identified, your variables populated during activation don't persist because activation causes a new page request. ie your code has effectively re-started by the time your admin_notices handler is called. So you need a mechanism to persist your $associati_error across page loads. The easiest is to use wordpress built-in ...


1

I like to keep my templates short and sweet, for this reason, bulky (or long pieces of) code like the code in your question, I tend move that into a function and then just call the function in my templates or use do_action() calls. I also split my functionalities between different functions files so that I don't end up with a functions.php which is 2000 ...


0

With your code given in OP, it is hard to exactly tell you where you are going wrong. One note on what I can, you should never use create_function(), it is a security thread that can be exploited by hackers. You should avoid using that completely. Rather make use of proper closures that was introduced in PHP 5.3. To help you, here is a basic skeleton which ...


2

That depends on what the plugin does, whether your theme relies on it and whether it is your own plugin or not. For example, when it's a plugin that adds a custom post type with special theme pages and stuff (like events or a portfolio), than you should integrate it in your theme using your second method. On the other hand, when it's a plugin from an ...


1

You need to insert your term after the init hook (i.e. when the taxonomy is registered): function create_tax() { $args = array(...); register_taxonomy('custom_tax', array('post'), $args); // Now we're safe $result = wp_insert_term('Test Term', 'custom_tax', array('parent'=>0) ); }


0

Finally i used the following code and i add category from my plug in. class MyPluginClass { public function __construct() { add_action( 'init', array( $this, 'sample_insert_category') ); } public function sample_insert_category() { if(!term_exists('Test','product_cat')) { wp_insert_term( 'Test', ...


1

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following... class MyPluginClass { public function __construct() { add_action( 'init', array( $this, 'sample_insert_category') ); } public function sample_insert_category() { ...


2

You can use get_pages(); or get_posts(); or WP_Query to get a list of pages. They differ somewhat in details, so read up on that. But generally all of them should suffice, for you to achieve your goal. Just choose the best fitting one for your purpose. For getting pages by name or better title you can use: get_page_by_title() Or use: ...


0

This is always a problem when using a plugin that loads extra css/js files. You could add custom fields to the pages where you want to exclude css and js files (called something like page_exclude_css and _js), with comma separated style and script handlers as it's values. Then you add a function to to the wp_enqueue hooks (at a position like 9999) that ...


0

WordPress doesn't operate with DOM for the purpose of page source generation from templates. Templates are treated and run as PHP source files, producing any and all output. Unless you have control over actual templates your options likely are: Attempting to buffer and rewrite output (rather fragile, more so for publicly released plugin) Adjust markup ...


1

prepare() is used to escape the values for example in the WHERE-statement. Usually it is anticipated the table selection is "hardcoded". If you can't use for example $wpdb->posts or the other "table"-functions, you could whitelist the allowed tables and check if $table_name is on this white list: <?php $allowed_tables = array( $wpdb->prefix . ...



Top 50 recent answers are included