base || 'themes' == $screen->base ) ) { return; } // Return early if the theme as not declared any plugin enhancements. if ( ! $this->theme_has_enhancements() ) { return; } // Get the plugin enhancements information declared by the theme. $this->plugins = $this->get_theme_plugin_enhancements(); // Return if no plugin enhancements have been declared by the theme. if ( ! $this->plugins ) { return; } /* Set the status of each of these enhancements and determine if a * notice is needed. */ $this->set_plugin_status(); // Output the corresponding notices in the admin. if ( $this->display_notice && current_user_can( 'install_plugins' ) ) { add_action( 'admin_notices', array( $this, 'admin_notices' ) ); } } /** * Checks whether the theme has declared any plugin enhancements. */ function theme_has_enhancements() { return current_theme_supports( 'theme-plugin-enhancements' ); } /** * Returns the plugin enhancements declared by the theme. */ function get_theme_plugin_enhancements() { $enhancements = get_theme_support( 'theme-plugin-enhancements' ); if ( ! is_array( $enhancements ) ) { return false; } else { return $enhancements[0]; } } /** * Determine the status of each of the plugins declared as a dependency * by the theme and whether an admin notice is needed or not. */ function set_plugin_status() { // Get the names of the installed plugins. $installed_plugin_names = wp_list_pluck( get_plugins(), 'Name' ); foreach ( $this->plugins as $key => $plugin ) { // Determine whether a plugin is installed. if ( in_array( $plugin['name'], $installed_plugin_names ) ) { /* Determine whether the plugin is active. If yes, remove if from * the array containing the plugin enhancements. */ if ( is_plugin_active( array_search( $plugin['name'], $installed_plugin_names ) ) ) { unset( $this->plugins[$key] ); } // Set the plugin status as to-activate. else { $this->plugins[$key]['status'] = 'to-activate'; $this->display_notice = true; } // Set the plugin status as to-install. } else { $this->plugins[$key]['status'] = 'to-install'; $this->display_notice = true; } } } /** * Display the admin notice for the plugin enhancements. */ function admin_notices() { $notice = ''; // Loop through the plugins and print the message and the download or active links. foreach( $this->plugins as $key => $plugin ) { $notice .= '
'; // Custom message provided by the theme. if ( isset( $plugin['message'] ) ) { $notice .= esc_html( $plugin['message'] ); } // Activation message if ( 'to-activate' == $plugin['status'] ) { $activate_url = $this->plugin_activate_url( $plugin['slug'] ); $notice .= sprintf( __( ' Please activate %1$s. %2$s', 'canard' ), esc_html( $plugin['name'] ), ( $activate_url ) ? '' . __( 'Activate', 'canard' ) . '' : '' ); } // Download message if ( 'to-install' == $plugin['status'] ) { $install_url = $this->plugin_install_url( $plugin['slug'] ); $notice .= sprintf( __( ' Please install %1$s. %2$s', 'canard' ), esc_html( $plugin['name'] ), ( $install_url ) ? '' . __( 'Install', 'canard' ) . '' : '' ); } $notice .= '
'; } // Output notice HTML. printf( '