includes(); if( $this->_themes_page() || $this->_dashboard_page() ) { add_action( 'init', array($this, 'set_settings') ); } add_action( 'admin_notices', array( $this , 'notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 50 ); add_action( 'admin_menu', array( $this, 'admin_menu_init' ), 9 ); add_action( 'wp_ajax_acoustics_install_starter_plugin', array( $this, 'install_starter_plugin' ) ); add_action('wp_ajax_acoustics_dismissed_handler', array($this, 'dismissed_handler')); add_action( 'acoustics_admin_content_before', array( $this, 'header_before'), 10 ); add_action( 'acoustics_admin_content_after', array( $this, 'footer_after'), 100 ); add_action('switch_theme', array($this, 'reset_notices')); add_action('after_switch_theme', array($this, 'reset_notices')); } public function set_settings() { $this->settings = apply_filters('acoustics_dashboard_settings', array() ); } public function get_settings() { return $this->settings; } public function notice(){ global $pagenow; $screen = get_current_screen(); if ( 'themes.php' === $pagenow && 'themes' === $screen->base ) { $transient_name = sprintf( '%s_hero_notice', get_template() ); if ( ! get_transient( $transient_name ) ) { ?>
wp_create_nonce( 'nonce' ), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'failed_message' => esc_html__( 'Something went wrong, contact support.', 'acoustics' ), ) ); } /** * Get plugin status. * * @param string $plugin_path Plugin path. */ public function get_plugin_status( $plugin_path ) { if ( ! current_user_can( 'install_plugins' ) ) { return; } if (!function_exists('is_plugin_active_for_network')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound } if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_path ) ) { return 'not_installed'; } elseif ( in_array( $plugin_path, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin_path ) ) { return 'active'; } else { return 'inactive'; } } /** * Install a plugin. * * @param string $plugin_slug Plugin slug. */ public function install_plugin( $plugin_slug ) { if ( ! current_user_can( 'install_plugins' ) ) { return; } if ( ! function_exists( 'plugins_api' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound } if ( ! class_exists( 'WP_Upgrader' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound } if ( false === filter_var( $plugin_slug, FILTER_VALIDATE_URL ) ) { $api = plugins_api( 'plugin_information', array( 'slug' => $plugin_slug, 'fields' => array( 'short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false, ), ) ); $download_link = $api->download_link; } else { $download_link = $plugin_slug; } // Use AJAX upgrader skin instead of plugin installer skin. // ref: function wp_ajax_install_plugin(). $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); $install = $upgrader->install( $download_link ); if ( false === $install ) { return false; } else { return true; } } /** * Activate a plugin. * * @param string $plugin_path Plugin path. */ public function activate_plugin( $plugin_path ) { if ( ! current_user_can( 'install_plugins' ) ) { return false; } $activate = activate_plugin( $plugin_path, '', false, true ); if ( is_wp_error( $activate ) ) { return false; } else { return true; } } /** * Install starter plugin. */ public function install_starter_plugin() { check_ajax_referer( 'nonce', 'nonce' ); $plugin_slug = (isset($_POST['slug'])) ? sanitize_text_field(wp_unslash($_POST['slug'])) : ''; $plugin_path = (isset($_POST['path'])) ? sanitize_text_field(wp_unslash($_POST['path'])) : ''; if ( ! current_user_can( 'install_plugins' ) ) { wp_send_json_error( esc_html__( 'Insufficient permissions to install the plugin.', 'acoustics' ) ); wp_die(); } if ( 'not_installed' === $this->get_plugin_status( $plugin_path ) ) { $this->install_plugin( $plugin_slug ); $this->activate_plugin( $plugin_path ); } elseif ( 'inactive' === $this->get_plugin_status( $plugin_path ) ) { $this->activate_plugin( $plugin_path ); } if ( 'active' === $this->get_plugin_status( $plugin_path ) ) { wp_send_json_success(); } wp_send_json_error( esc_html__( 'Failed to initialize or activate importer plugin.', 'acoustics' ) ); wp_die(); } public function header_before(){ ?>