Inventory_Presser_Plugin::hooks()

hooks


Description Description

This is the driver function of the entire plugin. Includes dependencies and adds all hooks.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: inventory-presser.php

	function hooks()
	{
		//include all this plugin's classes that live in external files
		$this->include_dependencies();

		INVP::add_hooks();

		//Allow translations
		add_action( 'plugins_loaded', function()
		{
			load_plugin_textdomain( 'inventory-presser', false, __DIR__ );
		} );

		//Modify the administrator dashboard
		$customize_dashboard = new Inventory_Presser_Customize_Dashboard();
		$customize_dashboard->hooks();


		/**
		 * Create our post type and taxonomies
		 */

		//create a custom post type for the vehicles
		add_action( 'init', array( $this, 'create_POST_TYPE' ) );

		//register all postmeta fields the CPT uses (mostly to expose them in the REST API)
		add_action( 'init', array( $this, 'register_meta_fields' ), 20 );


		//Create custom taxonomies
		$taxonomies = new Inventory_Presser_Taxonomies();
		$taxonomies->hooks();

		/**
		 * Some custom rewrite rules are created and destroyed
		 */

		//Add custom rewrite rules
		add_action('generate_rewrite_rules', array( $this, 'add_pretty_search_urls' ) );

		/**
		 * Activation and deactivation hooks ensure that the rewrite rules are
		 * flushed to add and remove our custom rewrite rules
		 */

		//Flush rewrite rules when the plugin is activated
		register_activation_hook( __FILE__, array( 'Inventory_Presser_Plugin', 'flush_rewrite' ) );

		//Delete an option during deactivation
		register_deactivation_hook( __FILE__, array( 'Inventory_Presser_Plugin', 'delete_rewrite_rules_option' ) );

		//Register some widgets included with this plugin
		add_action( 'widgets_init', array( $this, 'register_widgets' ) );

		/**
		 * Deliver our promise to order posts, change the ORDER BY clause of
		 * the query that's fetching post objects.
		 */

		$this->settings = INVP::settings();
		if( ! is_admin() )
		{
			add_action( 'pre_get_posts', array( $this, 'add_orderby_to_query' ) );
		}

		//Allow custom fields to be searched
		$add_custom_fields_to_search = new Add_Custom_Fields_To_Search();
		$add_custom_fields_to_search->hooks();

		//Redirect URLs by VINs to proper vehicle permalinks
		$allow_urls_by_vin = new Vehicle_URLs_By_VIN();
		$allow_urls_by_vin->hooks();

		//Add buttons near vehicles for Carfax reports or NextGear inspections
		$badges = new Inventory_Presser_Badges();
		$badges->hooks();

		//Redirect 404 vehicles to make archives
		$redirect_404_vehicles = new Redirect_404_Vehicles();
		$redirect_404_vehicles->hooks();

		//Include CSS on the frontend
		add_action( 'wp_enqueue_scripts', array( $this, 'include_scripts_and_styles' ), 11 );

		//Modify the URL of an "Email a Friend" menu item on the "Vehicle Details Buttons" menu
		$email_a_friend = new Inventory_Presser_Email_A_Friend();
		$email_a_friend->hooks();

		//Make it possible for a menu item to print the page
		$print_button = new Inventory_Presser_Menu_Item_Print();
		$print_button->hooks();

		/**
		 * When vehicle posts are inserted, make sure they create a relationship
		 * with the "For Sale" term in the Availabilities taxonomy. Some queries
		 * that honor the "Include Sold Vehicles" setting in this plugin will 
		 * exclude them without a relationship to a term in that taxonomy.
		 */
		add_action( 'save_post_' . INVP::POST_TYPE, array( $this, 'mark_vehicles_for_sale_during_insertion' ), 10, 3 );

		//Maybe skip the trash bin and permanently delete vehicles & photos
		add_action( 'trashed_post', array( $this, 'maybe_force_delete' ) );

		//When vehicles are deleted, delete their attachments, too
		add_action( 'before_delete_post', array( 'INVP', 'delete_attachments' ), 10, 1 );

		//Change links to our taxonomy terms to insert /inventory/
		add_filter( 'pre_term_link', array( $this, 'change_term_links' ), 10, 2 );

		//Change attachment URLs to prevent aggressive caching from showing users updated JPGs
		add_filter( 'wp_get_attachment_url', array( $this, 'change_attachment_urls' ) );

		//Allow users to set the Inventory listing page as the home page
		$page = new Inventory_Presser_Allow_Inventory_As_Home_Page();
		$page->hooks();

		//Add all our shortcodes
		$shortcodes = new Inventory_Presser_Shortcode_Grid();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Iframe();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Slider();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Single_Vehicle();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Archive();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Archive_Vehicle();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Hours_Today();
		$shortcodes->hooks();
		$shortcodes = new  Inventory_Presser_Shortcode_Photo_Slider();
		$shortcodes->hooks();

		/**
		 * When the active theme isn't prepared to display vehicles, insert
		 * our archive and single vehicle shortcodes.
		 */
		$template_provider = new Inventory_Presser_Template_Provider();
		$template_provider->hooks();

		//Add blocks
		$blocks = new Inventory_Presser_Blocks();
		$blocks->hooks();

		/**
		 * Add photo number meta values to vehicle photos uploaded in the
		 * dashboard
		 */
		$photo_numberer = new Inventory_Presser_Photo_Numberer();
		$photo_numberer->hooks();

		//Allow additional vehicle archives to be created
		$additional_archives = new Inventory_Presser_Additional_Listings_Pages();
		$additional_archives->hooks();

		if ( is_admin() )
		{
			//Initialize our Settings page in the Dashboard
			$options = new Inventory_Presser_Options();
			$options->hooks();

			//If the user is looking at our options page, suggest settings tweaks
			$settings_suggester = new Inventory_Presser_Settings_Suggester();
			$settings_suggester->hooks();

			//Add a sidebar to the editor when editing vehicles
			$sidebar = new Inventory_Presser_Editor_Sidebar();
			$sidebar->hooks();
		}

		$overlapper = new Inventory_Presser_Taxonomy_Overlapper();
		$overlapper->hooks();

		$uninstaller = new Inventory_Presser_Uninstaller();
		$uninstaller->hooks();

		$schema_generator = new Inventory_Presser_Schema_Org_Generator();
		$schema_generator->hooks();
	}