hooks(); $this->acfg_include_files(); } /** * Initialize. */ public function hooks() { add_action( 'admin_enqueue_scripts', array( $this, 'acfg_admin_scripts' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'acfg_front_scripts' ) ); } /** * Check ACF is active or not. */ public function acfg_validate_depencency() { if ( ! class_exists( 'ACF' ) ) { add_action( 'admin_notices', array( $this, 'acfg_validate_depencency_msg' ) ); return; } } /** * Displays an admin notice when Advanced Custom Fields (or its Secure Custom Fields successor) is missing or inactive. */ public function acfg_validate_depencency_msg() { $screen = get_current_screen(); if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) { return; } include_once ABSPATH . 'wp-admin/includes/plugin.php'; $plugin = 'advanced-custom-fields/acf.php'; $plugin_pro = 'advanced-custom-fields-pro/acf.php'; $plugin_scf = 'secure-custom-fields/secure-custom-fields.php'; $installed_plugins = get_plugins(); if ( isset( $installed_plugins[ $plugin ] ) || isset( $installed_plugins[ $plugin_pro ] ) || isset( $installed_plugins[ $plugin_scf ] ) ) { // Check if a supported plugin is installed. if ( ! current_user_can( 'activate_plugins' ) ) { return; } if ( isset( $installed_plugins[ $plugin_pro ] ) ) { $activate_plugin = $plugin_pro; $activate_label = __( 'Activate ACF Pro Now', 'acf-on-the-go' ); } elseif ( isset( $installed_plugins[ $plugin ] ) ) { $activate_plugin = $plugin; $activate_label = __( 'Activate ACF Now', 'acf-on-the-go' ); } else { $activate_plugin = $plugin_scf; $activate_label = __( 'Activate Secure Custom Fields Now', 'acf-on-the-go' ); } $activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $activate_plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $activate_plugin ); $message = '

' . __( 'ACF on the Go', 'acf-on-the-go' ) . '' . __( ' Plugin not working because you need to activate the Advanced Custom Fields or Secure Custom Fields plugin.', 'acf-on-the-go' ) . '

'; $message .= '

' . sprintf( '%s', esc_url( $activation_url ), $activate_label ) . '

'; } else { if ( ! current_user_can( 'install_plugins' ) ) { return; } $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=secure-custom-fields' ), 'install-plugin_secure-custom-fields' ); $message = '

' . __( 'ACF on the Go', 'acf-on-the-go' ) . '' . __( ' Plugin not working because you need to install the Advanced Custom Fields or Secure Custom Fields plugin', 'acf-on-the-go' ) . '

'; $message .= '

' . sprintf( '%s', esc_url( $install_url ), __( 'Install Secure Custom Fields Now', 'acf-on-the-go' ) ) . '

'; } echo '

' . wp_kses_post( $message ) . '

'; } /** * Enqueue admin panel required css/js. */ public function acfg_admin_scripts() { } /** * Load files. */ public function acfg_include_files() { include_once ABSPATH . 'wp-admin/includes/plugin.php'; $checkplugin = is_plugin_active( 'advanced-custom-fields/acf.php' ); $checkplugin_pro = is_plugin_active( 'advanced-custom-fields-pro/acf.php' ); $checkplugin_scf = is_plugin_active( 'secure-custom-fields/secure-custom-fields.php' ); if ( true === $checkplugin || true === $checkplugin_pro || true === $checkplugin_scf ) { include_once ACFG_DIR . 'includes/class-acfg-front-loader.php'; } } /** * Enqueue front-end required css/js. */ public function acfg_front_scripts() { if ( is_user_logged_in() ) { wp_enqueue_style( 'acfg-jquery-ui-dialog', ACFG_URL . 'assets/front/css/jquery-ui-dialog.min.css', array(), ACFG_VERSION ); wp_enqueue_style( 'acfg-editor', ACFG_URL . 'assets/front/css/medium-editor.min.css', array(), ACFG_VERSION ); wp_enqueue_style( 'acfg-css', ACFG_URL . 'assets/front/css/front-style.css', array(), ACFG_VERSION ); wp_enqueue_style( 'acfg-toaster', ACFG_URL . 'assets/front/css/jquery.toast.css', array(), ACFG_VERSION ); wp_enqueue_script( 'acfg-front-js', ACFG_URL . 'assets/front/js/front.js', array( 'jquery' ), ACFG_VERSION, false ); wp_enqueue_script( 'acfg-toster-js', ACFG_URL . 'assets/front/js/jquery.toast.js', array( 'jquery' ), ACFG_VERSION, false ); wp_enqueue_script( 'jquery-ui-core', '', array(), false, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion -- core-bundled script, version is managed by WordPress itself. wp_enqueue_script( 'jquery-ui-dialog', '', array(), false, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion -- core-bundled script, version is managed by WordPress itself. wp_enqueue_style( 'wp-jquery-ui-dialog' ); wp_localize_script( 'acfg-front-js', 'js_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'acfg_update_fields' ), 'success_txt' => __( 'Success', 'acf-on-the-go' ), 'nochange_txt' => __( 'No change', 'acf-on-the-go' ), 'success_msg' => __( 'Updated Successfully', 'acf-on-the-go' ), 'nochange_msg' => __( 'Nothing to change', 'acf-on-the-go' ), 'update_txt' => __( 'Update', 'acf-on-the-go' ), 'close_txt' => __( 'Close', 'acf-on-the-go' ), ) ); } } } } /* * Starts our plugin class, easy! */ new ACFG_Init();