Inventory_Presser_Plugin::hooks()

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


Return Return

(void)


Top ↑

Source Source

File: inventory-presser.php

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

		// 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();
		$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.
		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();
		$taxonomies->hooks();

		// Modify edit-tags.php for our location taxonomy to manage term meta.
		$location_meta = new Inventory_Presser_Admin_Location_Meta();
		$location_meta->add_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();

		// 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();
		$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.
		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_Attribute_Table();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Hours_Today();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Photo_Slider();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Vin();
		$shortcodes->hooks();
		$shortcodes = new Inventory_Presser_Shortcode_Sort_By();
		$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_Admin_Options();
			$options->hooks();

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

			// Add a sidebar to the editor when editing vehicles.
			$sidebar = new Inventory_Presser_Admin_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();

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

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

		$rest = new Inventory_Presser_REST();
		$rest->add_hooks();

		$wp_all_import = new Inventory_Presser_WP_All_Import();
		$wp_all_import->add_hooks();

		$contact_form_7 = new Inventory_Presser_Contact_Form_7();
		$contact_form_7->add_hooks();

		$photo_arranger = new Inventory_Presser_Admin_Photo_Arranger();
		$photo_arranger->add_hooks();

		// Change archive page titles.
		add_filter( 'document_title_parts', array( $this, 'change_archive_title_tags' ) );
	}