# datafeedr-api/1.4.3/classes/class-dfrapi-initialize.php

Datafeedr API, version 1.4.3. 159 lines.

- Page: https://pluginprobe.com/plugins/datafeedr-api/1.4.3/code/classes/class-dfrapi-initialize.php
- Raw: https://pluginprobe.com/plugins/datafeedr-api/1.4.3/raw/classes/class-dfrapi-initialize.php
- Modified: 2026-10-05T16:25:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/datafeedr-api/1.4.3/code/classes/class-dfrapi-initialize.php#L10-L20`.

```php
<?php

defined( 'ABSPATH' ) || exit;

if ( ! class_exists( 'Dfrapi_Initialize' ) ) {

	class Dfrapi_Initialize {

		public function __construct() {

			// Actions
			add_action( 'plugins_loaded', [ $this, 'initialize_classes' ] );
			add_action( 'admin_menu', [ $this, 'admin_menu' ] );
			add_action( 'admin_menu', [ $this, 'networks_menu' ], 20 );
			add_action( 'admin_menu', [ $this, 'merchants_menu' ], 30 );
			add_action( 'wp_ajax_search_form', [ $this, 'ajax_search_form' ] );

			// Datafeedr Admin Pages have been loaded. Broadcast "loaded" action.
			do_action( 'dfrapi_loaded' );
		}

		function ajax_search_form() {

			check_ajax_referer( 'dfrapi_search_form', 'dfrapi_security' );

			/**
			 * Filters the capability required to use the search form's AJAX handler.
			 *
			 * @since 1.4.3
			 *
			 * @param string $capability Default 'edit_posts'.
			 */
			$capability = apply_filters( 'dfrapi_search_form_capability', 'edit_posts' );

			if ( ! current_user_can( $capability ) ) {
				wp_die( -1, 403 );
			}

			$sform = new Dfrapi_SearchForm();
			echo $sform->ajaxHandler();
			die;
		}

		function admin_menu() {
			add_menu_page(
				__( 'Datafeedr API', 'datafeedr-api' ),
				__( 'Datafeedr API', 'datafeedr-api' ),
				'manage_options',
				'dfrapi',
				'',
				null,
				42
			);
		}

		public function networks_menu() {
			if ( dfrapi_datafeedr_api_keys_exist() ) {
				add_submenu_page(
					'dfrapi',
					__( 'Networks &#8212; Datafeedr API', 'datafeedr-api' ),
					__( 'Networks', 'datafeedr-api' ),
					'manage_options',
					'dfrapi_networks',
					array( $this, 'networks_output' )
				);
			}
		}

		public function networks_output() {
			$key  = 'dfrapi_networks';
			$page = 'dfrapi-networks';
			echo '<div class="wrap" id="' . $key . '">';
			echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
			echo '<form method="post" action="options.php">';
			submit_button();
			wp_nonce_field( 'update-options' );
			settings_fields( $page );
			do_settings_sections( $page );
			submit_button();
			echo '</form>';
			echo '<div id="dfr_unload_message" style="display:none">' .
			     __( 'You have unsaved changes', 'datafeedr-api' ) .
			     '</div>';
			echo '</div>';
		}

		public function merchants_menu() {
			if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_selected_network_count() > 0 ) {
				add_submenu_page(
					'dfrapi',
					__( 'Merchants &#8212; Datafeedr API', 'datafeedr-api' ),
					__( 'Merchants', 'datafeedr-api' ),
					'manage_options',
					'dfrapi_merchants',
					array( $this, 'merchants_output' )
				);
			}
		}

		function merchants_output() {
			$key  = 'dfrapi_merchants';
			$page = 'dfrapi-merchants';
			echo '<div class="wrap" id="' . $key . '">';
			echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
			echo '<form method="post" action="options.php">';
			submit_button();
			wp_nonce_field( 'update-options' );
			settings_fields( $page );
			do_settings_sections( $page );
			submit_button();
			echo '</form>';
			echo '<div id="dfr_unload_message" style="display:none">' .
			     __( 'You have unsaved changes', 'datafeedr-api' ) . '</div>';
			echo '</div>';
		}

		function initialize_classes() {

			new Dfrapi_Configuration();

			// Show "Networks" page if API keys are present.
			if ( dfrapi_datafeedr_api_keys_exist() ) {

				if ( isset( $_GET['page'] ) && 'dfrapi_networks' === $_GET['page'] && is_admin() ) {
					new Dfrapi_Networks();
				}

				if ( isset( $_POST['option_page'] ) && ( 'dfrapi-networks' === $_POST['option_page'] ) && is_admin() ) {
					new Dfrapi_Networks();
				}
			}

			// Show "Merchants" page if API keys are present AND a network is selected.
			if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_user_has_selected_networks() ) {

				if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_merchants' === $_GET['page'] ) {
					new Dfrapi_Merchants();
				}

				if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' === $_POST['option_page'] ) ) {
					new Dfrapi_Merchants();
				}
			}

			// Show Tools, Export and Import pages if API keys are present.
			if ( dfrapi_datafeedr_api_keys_exist() ) {
				new Dfrapi_Tools();
				new Dfrapi_Export();
				new Dfrapi_Import();
				new Dfrapi_Account();
			}
		}

	}

	$dfrapi_initialize = new Dfrapi_Initialize();

} // class_exists check

```
