Created
May 31, 2017 11:12
-
-
Save kish2011/e085ed0672bb1fac7214105e0dd02a2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :) | |
* @see https://github.com/herewithme/wp-filters-extras | |
*/ | |
function remove_filters_for_anonymous_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 ) { | |
global $wp_filter; | |
// Take only filters on right hook name and priority | |
if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) ) | |
return false; | |
// Loop on filters registered | |
foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { | |
// Test if filter is an array ! (always for class/method) | |
if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { | |
// Test if object is a class, class and method is equal to param ! | |
if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) { | |
// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/) | |
if( is_a( $wp_filter[$hook_name], 'WP_Hook' ) ) { | |
unset( $wp_filter[$hook_name]->callbacks[$priority][$unique_id] ); | |
} | |
else { | |
unset($wp_filter[$hook_name][$priority][$unique_id]); | |
} | |
} | |
} | |
} | |
return false; | |
} | |
function remove_already_applied_title_for_wpjm_applications() { | |
remove_filters_for_anonymous_class( 'the_title', 'WP_Job_Manager_Applications_Post_Types', 'already_applied_title', 10 ); | |
} | |
add_action( 'plugins_loaded', 'remove_already_applied_title_for_wpjm_applications', 99 ); | |
function add_already_applied_title_for_wpjm_applications() { | |
if (class_exists('WP_Job_Manager_Applications_Post_Types')) { | |
/** | |
* JOBSTER_Applications_Post_Types class. | |
*/ | |
class JOBSTER_Applications_Post_Types extends WP_Job_Manager_Applications_Post_Types { | |
/** | |
* __construct function. | |
*/ | |
public function __construct() { | |
add_filter( 'the_title', array( $this, 'already_applied_title' ), 1000, 2 ); | |
} | |
public function already_applied_title( $title, $post_id = '' ) { | |
if ( $post_id && 'job_listing' === get_post_type( $post_id ) && ! is_single() && empty( $_POST['wp_job_manager_resumes_apply_with_resume'] ) && empty( $_GET['download-csv'] ) && user_has_applied_for_job( get_current_user_id(), $post_id ) ) { | |
$title .= ' <span class="uk-bage uk-badge-primary job-manager-applications-applied-notice">' . __( 'Applied', 'wp-job-manager-applications' ) . '</span>'; | |
} | |
return $title; | |
} | |
} | |
} | |
new JOBSTER_Applications_Post_Types(); | |
} | |
add_action( 'plugins_loaded', 'add_already_applied_title_for_wpjm_applications', 999 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment