New answers tagged

0

I solved this, but maybe this isn't the most elegant solution: global $wpdb; $OrderItemMetaTable = $wpdb->base_prefix.'woocommerce_order_itemmeta'; $wpdb->update( $OrderItemMetaTable, array('order_item_id'=>$PreviousItemArrayKey), array('order_item_id'=>$key, 'meta_key'=>'pa_color'), array('%d'), array('%d', '%s') ); $wpdb->update( ...


0

Apparently "the_author" is an appropriate filter. Also, $author is apparently a universal variable, so this code worked out fine: add_filter("the_author", "change_author"); function change_author($author) { $author = "NEW AUTHOR!"; return $author; }


-1

if some one need take custom field by post type i leave the code below of the way I did and work fine for me :) function awh_field_type($post_id){ $awh_f_post = get_post_type($post_id); $meta_value = ''; $meta_name = 'custom'; if($awh_f_post == 'product'){ add_post_meta($post_id,$meta_name,$meta_value,true); } return $awh_f_post; } ...


0

Here is the final code to get sessions to write to the usermeta and delete on logout. This code works with WordPress 4.5.2. The code is for user_id information only. add_action( 'after_setup_theme', 'new_login' ); function new_login() { $user_id = ''; // Change your code to grab user_id from external source if ( $user_id > 0 && ! ...


0

WordPress has a fairly good roles and capabilities system already and, IMHO, you'd find it easier working with that. When the admin menu is constructed, every item on the admin menu is subject to a check on a relevant capability. Similarly every attempt to use an admin screen is checked. It's possible to use map_meta_cap to rework some of these ...


1

The reason hooks ( Filters and Actions ) are in these templates is specifically so you don't need to copy the templates into your theme folder. The biggest issue with copying WooCommerce templates into your theme is that often time whenever WooCommerce updates they also update the templates. Then you'll need to bring your changes from the old template into ...


1

wp_login_form is completely separate from wp-login.php - the login_form hook only applies to the latter. For the former, you've got three filters at your disposal: login_form_top - return HTML to be injected right after the opening <form /> tag login_form_middle - return HTML to be injected between the password field and the remember me/submit field ...


1

That is due to the fact, that your filter woocommerce_breadcrumb doesn't even exist. This filter here works and pulls out all the elements, that are currently in the breadcrumb (as an array): add_filter( 'woocommerce_get_breadcrumb', 'change_breadcrumb' ); function change_breadcrumb( $crumbs ) { var_dump( $crumbs ); return $crumbs; } And this ...


3

Files to look at: wp-admin/includes/wp-current-screen.php and wp-admin/admin-header.php If we take a look at admin-header.php we can see that $current_screen->render_screen_meta(); is the one responsible for rendering the contextual help on screens. It gets the global $current_screen which is set via WP_Screen class. It has methods like ...


1

To append text to the end of the titles in that widget and nothing more i.e. does not matter the URL, you can just use some CSS. <li> <a class="my-folder-categories">Category 1</a> </li> a.my-folder-categories-folder:after {content:" folder"; This will effectivly make the text appear as so: category 1 folder Be sure to add ...


0

I've found the exact solution to my question here: http://wordpress.stackexchange.com/a/17687/92505 Here's the exact code I used after some modification to make it work on my situation. Add the following code to functions.php where 'sidebar-1' is your sidebar ID. 'recent-posts' is the name of the widget your want yo hide. 12 is the length of the string ...


4

Conditional if ( isset($wp_filter['all']) ) { you can find right in these hook creating functions: apply_filters apply_filters_ref_array do_action do_action_ref_array The difference between these are in number of arguments sent. Either we need multiple arguments, thus ref_array or single argument. The other difference "action vs. filter" is simple, ...


6

all is just a string the WordPress developers picked to behave differently than any other hook. When you attach to all, your callback will fire for all other hooks. I wouldn't spend too much time looking at the source of do_action, just know that: add_action( 'x', 'whatever' ) will mean whatever fires for do_action( 'x' ) add_action( 'all', 'whatever' ) ...


1

I suggest post status transitions that runs only when your set conditions are met. Example: add_action( 'transition_post_status', 'add_awesome_terms', 10, 3 ); function add_awesome_terms( $new_status, $old_status, $post ) { // only run when it's a page, new status is publish and old status isn't publish if ( $post->post_type == 'page' ...


0

Complete code (thanks to @birgire) in case anyone else finds useful in the future: // Append Tags as Hashtags to Jetpack publicise posts if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) { function tsj_publicize_hashtags() { $post = get_post(); if ( ! empty( $post ) ) { /* Grab the tags and ...


2

Just some general remarks: Why isn't the following change working? $custom_message = get_the_title( $post->ID ) .''. $hash_tags; to: $custom_message = get_the_content( $post->ID ) .' '. $hash_tags; Note that get_the_content() doesn't take a post ID as an input parameter and it depends on global variables, like $pages that's ...


0

I have added extra rewrite rules for pages with no item_width and item_height in combination with pagination as follows: /** * Adds rewrite rules for shop category */ function gtp_add_shop_rewrite_rules() { // shop-category/category/item_width/item_height/page/2/ add_rewrite_rule( '^shop-category\/([^/]*)\/([^/]*)\/([^/]*)\/page\/([0-9]*)$', ...


3

Loosely what you have should work already. However few things are off. Calling these function without time format will produce values like 1:36 pm (depending on your site's settings), which are not exactly comparable. Post modified time can be less than published in some cases, like scheduled posts. So I would write it along the lines of: if ( ...


1

Check the documentation of add_filter() first argument is name of filter and second one is callback function name. (both are required) See the example for your case:- add_filter('bimber_facebook_sdk_src', 'change_fb_sdk_url'); function change_fb_sdk_url($current_url) { // Variable $current_url hold the current value of URL // You can manipulate ...


1

You can use the_content with an high prioriety (lower number). add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, 0); You can even use negative priority: add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, -10); Note that this will apply everytime 'the_content' is used, no matter ...


1

There is no other global filter applied before the_content - you can use the $priority argument in your add_filter call to ensure your function runs before any others: function wpse_225625_to_the_top( $content ) { return "Hello World\n\n\$content"; } add_filter( 'the_content', 'wpse_225625_to_the_top', -1 /* Super important yo */ );


0

Use a static method - the add_action will fire for each instantiation, but the hook will only be registered once: add_action( 'wp_enqueue_scripts', __CLASS__ . '::planner_load_scripts' ); static public function planner_load_scripts() { }


0

I found this answer partly the question, // check for the existence of "some_hook_filter" filter if( array_key_exists( 'some_hook_filter' , $GLOBALS['wp_filter']) ) { //do your code here } However, as noted by the original contributor, this will not turn up all possible filters depending on when the code executes. Theme contributed filters will not show ...


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

add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) Hook a function or method to a specific filter action. WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime. A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each ...


0

This is how I bootstrapped youtube embeds in one of my projects. /** * Responsive Youtube embeds. */ add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) { $html = sprintf('<div class="embed-responsive ...


1

The delete_attachment action is fired when wp_delete_attachment() function is called to delete an item in the media library.



Top 50 recent answers are included