Description Description

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

Top ↑

Return Return


Top ↑

Source Source

File: inventory-presser.php

	function hooks()
		//include all this plugin's classes that live in external files

		//Translate friendly names to actual custom field keys and the other way
		add_filter( 'invp_prefix_meta_key', array( 'INVP', 'translate_custom_field_names' ) );
		add_filter( 'invp_unprefix_meta_key', array( 'INVP', 'untranslate_custom_field_names' ) );

		//Modify the administrator dashboard
		$customize_dashboard = new Inventory_Presser_Admin_Customize_Dashboard();

		 * 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 );

		//Filter the attachment post type to make sure `parent` is exposed in the REST API
		add_filter( 'register_post_type_args', array( $this, 'edit_attachment_post_type' ), 10, 2 );

		//Create custom taxonomies
		$taxonomies = new Inventory_Presser_Taxonomies();

		//Modify edit-tags.php for our location taxonomy to manage term meta
		$location_meta = new Inventory_Presser_Admin_Location_Meta();

		 * 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();

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

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

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

		//Register scripts and styles on the frontend and in the block editor
		add_action( 'wp_enqueue_scripts', array( $this, 'include_scripts_and_styles' ), 11 );
		add_action( 'enqueue_block_editor_assets', 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();

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

		 * 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();

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

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

		//Add blocks
		$blocks = new Inventory_Presser_Blocks();

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

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

		if ( is_admin() )
			//Initialize our Settings page in the Dashboard
			$options = new Inventory_Presser_Admin_Options();

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

			//Add a sidebar to the editor when editing vehicles
			$sidebar = new Inventory_Presser_Admin_Editor_Sidebar();

		$overlapper = new Inventory_Presser_Taxonomy_Overlapper();

		$uninstaller = new Inventory_Presser_Uninstaller();

		$schema_generator = new Inventory_Presser_Schema_Org_Generator();

		add_action( 'invp_archive_buttons', array( $this, 'add_view_details_button' ) );

		add_action( 'plugins_loaded', array( $this, 'loaded' ) );

		$rest = new Inventory_Presser_REST();