$GLOBALS[‘hook_suffix’] variable empty

I thing you are missing the context. $GLOBALS[‘hook_suffix’] is available on any action fired after admin_init. Now, if you tried something like add_action( ‘admin_footer-‘. $GLOBALS[‘hook_suffix’], ‘myfunction’ ) outside of any function, you are not going to get anything. But if you do it – add_action(‘admin_menu’, ‘do_hook_to_footer’) and put the earlier hook within the do_hook_to_footer function, … Read more

Adding the hook ‘vc_before_init’ inside a object

I found the solution… First I thought the problem had something to do with wrapping the hook inside a class.. But after some more testing (sometimes you need to take a step back), it appears the hook vc_before_init has already fired on the init hook with the (default) priority of 10… My current theme (Salient) … Read more

Better action hook for creating table than after_switch_theme and switch_theme action hook

Ah I found it. You can use after_setup_theme action hook. So it will be like add_action(‘after_setup_theme’, [‘\Recruitment\recruitment’, ‘create_table’]); Updated Code $theme = wp_get_theme(); if ( $theme->name == ‘My THEME NAME’ ) { global $wpdb; global $charset_collate; $sql = “CREATE TABLE IF NOT EXISTS … $charset_collate;”; require_once ABSPATH . ‘wp-admin/includes/upgrade.php’; dbDelta( $sql ); add_option( ‘ab_db_version’, self::$db_version … Read more

Add meta field after post has been published

You can hook into post_updated action, if you want to access the post’s data after it’s been published. This hook passes the post’s ID, inundated post object, and updated post object. add_action( ‘post_updated’, ‘update_event_date’, 10, 3 ); function update_event_date( $post_id, $post_after, $post_before ){ $post_type = get_post_type( $post_id ); $event_datee = get_post_meta( $post_id, ‘_EventStartDate’, true ); … Read more

How to get $tag to fill into add_action() or add_filter()?

These 2 function add_action() and add_filter() are magics of WP and do not directly affect your code. In WordPress, they use hooks for mocking into existing functions, methods without changing it’s code. The $tag you are referring is the name of the hook that you want to use. List of core hooks can be found … Read more

Write automatic title at save_post (infinite loop)

There is a simple way, You need to use filter hook wp_insert_post_data So the code should be like add_filter( ‘wp_insert_post_data’, ‘set_post_title_with_field_value’ ); function set_post_title_with_field_value( $data ) { if ($data[‘post_type’] == ‘sentence’ ){ $sentence_number = get_field(‘sentencia_no’, $data[‘ID’]); $data[‘post_title’] = $sentence_number; } return $data; } You need to add this code into theme’s functions.php. So try the … Read more

How can I trigger actions manually?

You are currently using an anonymous function. The first step would be changing it to a named function so you can retrieve it from the wp_filter global array, which holds all the registered actions and filters. You’d do it like this: function payment_test($form, $entry_id){ if ( function_exists( ‘gf_webhooks’ ) ) { $entry = GFAPI::get_entry( $entry_id … Read more

How to track post number on the_loop

This should do it: $real_current_post = $wp_query->current_post + 1; switch( $real_current_post ){ case 2: // Do something for 2 break; case 5: // Do something for 5 break; case 7: // Do something for 7 break; } You may need to globalize $wp_query, but as long as you’re using the normal template hierarchy, it should … Read more

Remove action from shortcode

I do not want to removing and re-adding shortcode, because there is huge function beyond it. This might not answer your question, but the size of the shortcode function itself does not make much of a difference for removing and re-adding. Short or long functions take the same time here. So don’t hinder yourself removing … Read more

add_action in class and use it in theme

I recommend to add a static method to access the plugin instance. Example, taken from this answer: class My_Plugin { private $var=”foo”; protected static $instance = NULL; public static function get_instance() { // create an object NULL === self::$instance and self::$instance = new self; return self::$instance; // return the object } public function __construct() { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)