Inventory_Presser_Taxonomies::hooks()

hooks


Description Description

Adds hooks to register and manage our taxonomies


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-taxonomies.php

	function hooks()
	{
		//create custom taxonomies for vehicles
		add_action( 'init', array( $this, 'register_taxonomies' ) );
		add_action( 'init', array( $this, 'register_meta' ) );

		add_action( 'invp_delete_all_data', array( $this, 'delete_term_data' ) );

		// location taxonomy admin actions
		add_action( 'location_add_form_fields', array( $this, 'add_location_fields'), 10, 2 );
		add_action( 'location_add_form_fields', array( $this, 'add_location_fields_javascript'), 11, 1 );
		add_action( 'created_location', array( $this, 'save_location_meta'), 10, 2 );
		add_action( 'location_edit_form_fields', array( $this, 'edit_location_field'), 10, 2 );
		add_action( 'edited_location', array( $this, 'save_location_meta'), 10, 2 );

		//Sort some taxonomy terms as numbers
		add_filter( 'get_terms_orderby', array( $this, 'sort_terms_as_numbers' ), 10,  3 );

		//Save custom taxonomy terms when posts are saved
		add_action( 'save_post_' . INVP::POST_TYPE, array( $this, 'save_vehicle_taxonomy_terms' ), 10, 2 );

		//Load our scripts
		add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) );

		//Do not include sold vehicles in listings unless an option is checked
		add_action( 'pre_get_posts', array( $this, 'maybe_exclude_sold_vehicles' ) );

		/**
		 * Run a weekly cron job to delete empty terms and update term counts.
		 * The counts aren't always updated when deleting vehicles, and I'm not
		 * yet able to reproduce the bug in local copies of the sites.
		 */
		add_action( self::CRON_HOOK_DELETE_TERMS, array( $this, 'delete_unused_terms' ) );
		add_action( self::CRON_HOOK_DELETE_TERMS, array( $this, 'update_term_counts' ) );

		//Put terms into our taxonomies when the plugin is activated
		register_activation_hook( INVP_PLUGIN_FILE_PATH, array( 'Inventory_Presser_Taxonomies', 'populate_default_terms' ) );
		//Schedule a weekly wp-cron job to delete empty terms in our taxonomies
		register_activation_hook( INVP_PLUGIN_FILE_PATH, array( 'Inventory_Presser_Taxonomies', 'schedule_terms_cron_job' ) );
		//Remove the wp-cron job during deactivation
		register_deactivation_hook( INVP_PLUGIN_FILE_PATH, array( 'Inventory_Presser_Taxonomies', 'remove_terms_cron_job' ) );
	}