Tag Info

New answers tagged

-1

do_action is an event and there are many of them throughout your WordPress instance, in the core or your themes and plugins. (Hypothetical) So even when you put an add_action in your plugin file but the theme files are read first by order of execution your add_action function will still fire at that event or time of the do_action it is hooked to. This is ...


0

The WordPress environment is not yet fully initialized when your plugin files are loaded, it's almost always too early to safely run code that interacts with core at that point. WordPress achieves its initial state through a process which contains its own set of actions and filters, so plugins load before that happens to allow them to hook into that ...


0

Considering the comments and wasting a few more hours searching for a solution I came to the conclusion I have to review my plugin design. There are two promising approaches: Using a template file and provide a fallback. Providing a "shorttag" generator and make the user to create a post / page for each needed category. Thanks for your participation and ...


0

After some extended debugging we found the issue. The plugin uses Google's url shortener api, which uses an api key for any kind of large volume. Our dev instance (more accurately the public ip assoiated with it) was under the threshold for not needing a key. Production was over but there wasn't adequate error handling to see what had happened. We now can ...


0

At the office we use a combination of rewrite rules and adding a custom function to template_redirect A rewrite rule you could use is the following (untested): add_rewrite_rule( 'property/([0-9]+)/?', 'index.php?property=$matches[1]', 'top' ); Of course you need to flush the rewrite rules, that page has good examples. Don't do this on every pageload! ...


1

And there is your issue — WordPress does need to understand URL. Otherwise it is indeed 404 because it doesn't correspond to anything WP “knows”. You need to create that understanding, for example by using Rewrite API. Also since your data is external and isn't really a part of WP context, you will probably need to override 404 decision as well in the end.


-1

Just call wp-color-picker script without creating a function: wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'my-script-handle', plugins_url('js/my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );


0

You shouldn't put quotes around the index for HTML names - otherwise you end up with 'single_images' (including single quotes) as the PHP name (so you'd have to address it $iwmp_options["'single_images'"], which some might consider confusing) ... eg: add_action( 'admin_init', function () { register_setting( 'iwmp_settings', 'iwmp_settings' ); ...


0

I was having the same issue recently, until I followed an example from the Wordpress Codex which suggests using action hooks to run the function. I think if you add the following... add_action( 'recalculate_all_scores_hook', 'recalculate_all_scores' ); ...and amend the wp_schedule_event function to use the action hook name rather than the function ...


0

use php best practices. Wordpress itself doesn't always follows them, but that is not an excuse to repeat those mistakes. use the wordpress APIs as much as possible, don't re-invent the wheel. Avoid constructing your own SQL queries. unless you create new tables. Store data at relevant built-in data structure and uer the api to read and write it your ...


0

I know this is a dead horse and that Chip has pretty much covered it, but wanted to add a few thoughts. If you make a living programming and find yourself working on wordpress sites under deadlines, you are going to find that it really comes down to time. More often than not, especially for those just starting out, it is much faster and simpler to just add ...


0

I think you are looking for the function "add_rewrite_rule". You can register regex url matches that get redirected to you plugin file, which handles the request: add_action( 'init', 'my_rewrite' ); function my_rewrite() { global $wp_rewrite; add_rewrite_rule('list-data/$', WP_PLUGIN_URL . '/data-fetcher/list-data.php', 'top'); ...


0

If your plugin have to completely control the output of the page, i.e. not taking into account the active theme or other installed plugins, than you can simply prevent WordPress handle that url. For example: add_action('init', function() { if (trim(add_query_arg(array()), '/') === 'book-search') { require_once plugin_dir_path( __FILE__ ) . ...


0

The common options are the following: Provide a shortcode to use in page's content. Implement as page template, unfortunately needs to be in theme, WP really doesn't like to let plugins do this. Implement virtual page, for example with endpoint. There are more, ranging from uncommon to outright exotic. But without getting too crazy you should probably ...


0

Choose one file to be the main file of the plugin. From it, use require_once( plugin_dir_path( __FILE__ ) . 'another-file.php' ); for each of the other files you want to include. This means the rest of the files no longer need the plugin comment header, just the actual code that does whatever you need it to.


1

What you need is the function_exists method you would use it like this when defining your returnJs function: if( ! function_exists('returnJs') ){ function returnJs(){ //Code goes here } } However, better practice would be to just define the returnJs function in your plugin


1

Reason was simple: "wp-plugin-in-github" tool has not any delete assets functions. So in git repo there were no screenshot-1.png, but in svn repo — it was. See: https://github.com/sudar/wp-plugin-in-github/blob/e5a004052342cbdfc5bd7fbcb844fffce8695f91/deploy-plugin.sh#L231 Workaround to work: find $SVNPATH_ASSETS -type f -not -path '*.svn*' -delete cp ...


0

You already have <option value="">...</option> you just need some extra attrs for it You need to load current value and if value equals $page->ID than add attr selected="selected" Here's how it could be done: <select name="easyreg_redirect_page"> <option selected="selected" disabled="disabled" value=""><?php echo ...


-4

-EDIT- Because some people need more "information" On this Thursday January 22nd 2015, you can find on the following 2 links how to setup PHPStorm to work with WordPress (I'm sorry if later on those links don't work anymore). https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm ...


-1

This is the best way I know to do it from code http://salferrarello.com/wordpress-plugin-add-settings-link/


1

The answer is — you can't because WordPress can't. There is no dependency management concept in WP and it was the same case before Composer had even existed. The rise of autoload (Composer or otherwise) slightly helps with it, since you might just be getting different copy loaded (hopefully close enough) rather than outright fatal error. You can check for ...


0

You should be able to do something like this: register_activation_hook(__FILE__, 'my_plugin_activate'); add_action('admin_init', 'my_plugin_redirect'); function my_plugin_activate() { add_option('my_plugin_do_activation_redirect', true); } function my_plugin_redirect() { if (get_option('my_plugin_do_activation_redirect', false)) { ...


1

Ive run into things similar from time to time. What I've ended up doing when using custom post types and taxonomies is the following: Setup a callback on init (before 10) to register taxonomies. Setup another on init (before 10) to register post types. Setup another on 10 to relate them, maybe later if working with other peoples custom taxonomies and post ...


2

WP plugins are meant to be loaded in context of WordPress core load. They won't work as vanilla PHP, unless you purposely abstract some parts completely away from WordPress. The typical practice is to have actual working WP installation locally and develop in its context.


0

The problem with calling flush_rewrite_rules() is that the rules instantly get regenerated, while your plugin's hooks are still active. What I usually do, because it's the simplest route to success, is delete the rewrite_rules option on activation/deactivation. The rules will then get regenerated on the next pageload instead of the current one: ...


0

Generally said, there should nothing be happening before the get_header() call. So initiate your class if is_page() is true via wp_head action hook. Example: add_action( 'wp_head', 'initiate_my_class' ); function initiate_my_class() { if ( is_page() ) { //code } } Edit: As @AndrewBartel in his comment said you can globalize your variable ...


0

As I've explained elsewhere, you can modify the image sizes of the get_post_gallery() or get_post_gallery_images() with a simple filter: // Add a filter for full gallery size: add_filter( 'shortcode_atts_gallery','wpse_full_size_gallery' ); $gallery = get_post_gallery( get_the_ID(), false ); // Remove the filter: remove_filter( ...


0

Another different approach is just adding a hidden input field to the form: <input type="hidden" name="page" value="your-page-slug" /> This way, WordPress seems to handle the redirect automatically.


0

After analyzing the things, I have figured out that we can simply achieve it by following these steps : 1) Firstly create a WordPress page. 2) Create a separate custom page template for it and put the short-code there. 3) Remove the header (get_header) and footer (get_footer) from the page in case you want only the short-code content. 4) Create an ...


0

If you want it to show on 3-rd website, wich is not wordpress or isn't using your plugin than the only way is to use iframe Aldought there might be better solutions, i would do it these way: Create ajax action ( wp_ajax_nopriv_.... ) in callback write the code that should echo ( your shortcode ). see example under a list add some feature that will ...


0

Hook in when a post is deleted, check for the post type, then manipulate post_parent of potential child posts (or delete the posts): function wp_dev_174635_update_posts( $parent_id ) { $parent = get_post( $parent_id ); if ( $parent->post_type !== 'type2' ) { return; } $posts = get_posts( array( 'post_type' => ...


0

Try with changing your code like this..hope it will work function sam() { wp_enqueue_script('wp-color-picker', plugins_url('wp-color-picker-script.js', __FILE__ ), array( 'farbtastic' ), false, true ); } add_action( 'admin_enqueue_scripts', 'sam' ); In your template <div class="color-picker" style="position: relative;"> <input type="text" ...


1

As an alternative, you can make use of the 'transition_post_status' hook for this. This hook is fired whenever a post's status is changed. In your case, you need to check whether the old and new status of the post is the same, which is publish You can also set conditionals according to $post, which is the current post being updated/published etc. You can ...


0

This error is showing because you have script_debug is set on . turn it off . define('SCRIPT_DEBUG', false); I know its not a good solution but i m unable to find the other way around. Looks like bug in wp core.


1

You can user Milo 's answer or you can use the conditional inside the hooked function, and then compare the post_date and the post_modified. add_action('save_post', array($this, 'updatePost'), 10, 3); function updatePost($post_id){ // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; $post = ...


1

You can use post status transition actions for this. function wpd_updating_a_published_post( $post ){ // do something } add_action( 'publish_to_publish', 'wpd_updating_a_published_post', 10, 1 );


1

I am author of commenter data plugin. I have addressed your concern and released version 2.1 which allows you to set the capability. Please take a look and let me know if you have any further query.


0

add_action('loop_start', 'slider_function'); function slider_function() { if ( function_exists( 'soliloquy_slider' ) ) { soliloquy_slider(); }} Something like this custom function added to your functions file will enable you to hook in the sliders template tag so it displays before the content. This assumes using the Soliloquy slider plugins template tag. ...


6

Try to keep the business logic out of the theme. Dealing with images is always an edge case, because they do affect presentation, which is usually a theme job. But the logic of how to get and order these images, the JavaScript parts and the backend are probably better in a separate code base. That is also easier for version control, because you can focus on ...


1

Hooks are going to be your best friend here. You can filter post content by using the the_content filter for example: add_filter('the_content', 'wse_174099_append_to_content'); function wse_174099_append_to_content( $content ) { //get your data $custom_items = get_option( 'option_name' ); $content .= wpautop( $custom_items ); //always ...


0

First, let me say that you are wrong saying that the function works if you use outside a class. That is not correct and you can verify using this (it is the exact method of your class written and executed as function: //Define the function function xenword_add_wp_user() { /** * @since 1.0.6 * Insert the current user into the wp_users and ...



Top 50 recent answers are included