base, array( 'dashboard', 'themes', 'plugins' ) ) ) { return; } // Get the plugin enhancements information declared by the theme. $this->dependencies = $this->get_theme_dependencies(); // Return early if we have no plugin dependencies. if ( empty( $this->dependencies ) ) return; // Otherwise, build an array to list all the necessary dependencies and modules. $dependency_list = ''; $this->modules = array(); // Create a list of dependencies. foreach ( $this->dependencies as $dependency ) : // Add to our list of recommended modules. if ( 'none' !== $dependency['module'] ) : $this->modules[ $dependency['name'] ] = $dependency['module']; endif; // Build human-readable list. $dependency_list .= $dependency['name'] . ' (' . $this->get_module_name( $dependency['module'] ) . '), '; endforeach; // Define our Jetpack plugin as a necessary plugin. $this->plugins = array( array( 'slug' => 'jetpack', 'name' => 'Jetpack by WordPress.com', 'message' => sprintf( esc_html__( 'The %1$s is necessary to use some of this theme’s features, including: ', 'bushwick' ), '' . esc_html__( 'Jetpack plugin', 'bushwick' ) . '' ), 'modules' => rtrim( $dependency_list, ', ' ) . '.', ), ); // Set the status of each of these enhancements and determine if a notice is necessary. $this->set_plugin_status(); $this->set_module_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' ) ); } } /** * Let's see which modules (if any!) this theme relies on. */ function get_theme_dependencies() { $dependencies = array(); if ( current_theme_supports( 'site-logo' ) ) : $dependencies['logo'] = array( 'name' => esc_html__( 'Site Logo', 'bushwick' ), 'slug' => 'site-logo', 'url' => '', 'module' => 'none', ); endif; if ( current_theme_supports( 'featured-content' ) ) : $dependencies['featured-content'] = array( 'name' => esc_html__( 'Featured Content', 'bushwick' ), 'slug' => 'featured-content', 'url' => '', 'module' => 'none', ); endif; if ( current_theme_supports( 'jetpack-social-menu' ) ) : $dependencies['social-menu'] = array( 'name' => esc_html__( 'Social Menu', 'bushwick' ), 'slug' => 'jetpack-social-menu', 'url' => '', 'module' => 'none', ); endif; if ( current_theme_supports( 'nova_menu_item' ) ) : $dependencies['menus'] = array( 'name' => esc_html__( 'Menus', 'bushwick' ), 'slug' => 'nova_menu_item', 'url' => '', 'module' => 'custom-content-types', ); endif; if ( current_theme_supports( 'jetpack-comic' ) ) : $dependencies['comics'] = array( 'name' => esc_html__( 'Comics', 'bushwick' ), 'slug' => 'jetpack-comic', 'url' => '', 'module' => 'custom-content-types', ); endif; if ( current_theme_supports( 'jetpack-testimonial' ) ) : $dependencies['testimonials'] = array( 'name' => esc_html__( 'Testimonials', 'bushwick' ), 'slug' => 'jetpack-testimonial', 'url' => '', 'module' => 'custom-content-types', ); endif; if ( current_theme_supports( 'jetpack-portfolio' ) ) : $dependencies['portfolios'] = array( 'name' => esc_html__( 'Portfolios', 'bushwick' ), 'slug' => 'jetpack-portfolio', 'url' => '', 'module' => 'custom-content-types', ); endif; if ( current_theme_supports( 'jetpack-content-options' ) ) : $dependencies['content-options'] = array( 'name' => esc_html__( 'Content Options', 'bushwick' ), 'slug' => 'jetpack-content-options', 'url' => '', 'module' => 'none', ); endif; return $dependencies; } /** * Set the name of our modules. This is just so we can easily refer to them in * a nice, consistent, human-readable way. * * @param string $module The slug of the Jetpack module in question. */ function get_module_name( $module ) { $module_names = array( 'none' => esc_html__( 'no specific module needed', 'bushwick' ), 'custom-content-types' => esc_html__( 'Custom Content Types module', 'bushwick' ), ); return $module_names[ $module ]; } /** * Determine the status of each of the plugins declared as a dependency * by the theme and whether an admin notice is necessary 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; } } } /** * For Jetpack modules, we want to check and see if those modules are actually activated. */ function set_module_status() { $this->unactivated_modules = array(); // Loop through each module to check if it's active. foreach ( $this->modules as $feature => $module ) : if ( class_exists( 'Jetpack' ) && ! Jetpack::is_module_active( $module ) ) : // Add this feature to our array. $this->unactivated_modules[ $module ][] = $feature; $this->display_notice = true; endif; endforeach; } /** * Display the admin notice for the plugin enhancements. */ function admin_notices() { // Bail if the user has previously dismissed the notice (doesn't show the notice) if ( get_user_meta( get_current_user_id(), 'bushwick_jetpack_admin_notice', true ) === 'dismissed' ) { return; } $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 .= $plugin['message']; $notice .= esc_html( $plugin['modules'] ); } // Activation message. if ( 'to-activate' === $plugin['status'] ) { $activate_url = $this->plugin_activate_url( $plugin['slug'] ); $notice .= sprintf( esc_html__( ' Please activate %1$s. %2$s', 'bushwick' ), esc_html( $plugin['name'] ), ( $activate_url ) ? '' . esc_html__( 'Activate', 'bushwick' ) . '' : '' ); } // Download message. if ( 'to-install' === $plugin['status'] ) { $install_url = $this->plugin_install_url( $plugin['slug'] ); $notice .= sprintf( esc_html__( ' Please install %1$s. %2$s', 'bushwick' ), esc_html( $plugin['name'] ), ( $install_url ) ? '' . esc_html__( 'Install', 'bushwick' ) . '' : '' ); } $notice .= '
'; } // Output a notice if we're missing a module. foreach ( $this->unactivated_modules as $module => $features ) : $featurelist = array(); foreach ( $features as $feature ) { $featurelist[] = $feature; } if ( 2 === count( $featurelist) ) { $featurelist = implode( ' or ', $featurelist ); } elseif ( 1 < count( $featurelist ) ) { $last_feature = array_pop( $featurelist ); $featurelist = implode( ', ', $featurelist ) . ', or ' . $last_feature; } else { $featurelist = implode( ', ', $featurelist ); } $notice .= ''; $notice .= sprintf( esc_html__( 'To use %1$s, please activate the Jetpack plugin’s %2$s.', 'bushwick' ), esc_html( $featurelist ), '' . esc_html( $this->get_module_name( $module ) ) . '' ); $notice .= '
'; endforeach; // Output notice HTML. $allowed = array( 'p' => array(), 'strong' => array(), 'em' => array(), 'b' => array(), 'i' => array(), 'a' => array( 'href' => array() ), ); printf( '