is_plugin_active( $slug . '/' . $slug . '.php' ), 'needs' => $needs, ); } return array( 'status' => false, 'needs' => 'install', ); } /** * Create the install/activate button link for plugins * * @param plugin-state $state The plugin state (not installed/inactive/active). * @param plugin-slug $slug The plugin slug. * * @return mixed */ public function create_action_link( $state, $slug ) { switch ( $state ) { case 'install': return wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $slug, ), network_admin_url( 'update.php' ) ), 'install-plugin_' . $slug ); break; case 'deactivate': return add_query_arg( array( 'action' => 'deactivate', 'plugin' => rawurlencode( $slug . '/' . $slug . '.php' ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $slug . '/' . $slug . '.php' ), ), network_admin_url( 'plugins.php' ) ); break; case 'activate': return add_query_arg( array( 'action' => 'activate', 'plugin' => rawurlencode( $slug . '/' . $slug . '.php' ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $slug . '/' . $slug . '.php' ), ), network_admin_url( 'plugins.php' ) ); break; }// End switch(). } /** * Call plugin API to get plugins info * * @param plugin-slug $slug The plugin slug. * * @return mixed */ public function call_plugin_api( $slug ) { include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); $call_api = get_transient( 'cust_notice_plugin_info_' . $slug ); if ( false === $call_api ) { $call_api = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'downloaded' => false, 'rating' => false, 'description' => false, 'short_description' => true, 'donate_link' => false, 'tags' => false, 'sections' => false, 'homepage' => false, 'added' => false, 'last_updated' => false, 'compatibility' => false, 'tested' => false, 'requires' => false, 'downloadlink' => false, 'icons' => false, ), ) ); set_transient( 'cust_notice_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS ); } return $call_api; } /** * Add custom parameters to pass to the JS via JSON. * * @since 1.0.0 * @access public * @return array */ public function json() { $json = parent::json(); global $bulk_recommended_plugins; global $install_button_label; global $activate_button_label; global $deactivate_button_label; $customize_plugins = array(); $show_recommended_plugins = get_option( 'bulk_show_recommended_plugins' ); foreach ( $bulk_recommended_plugins as $slug => $plugin_opt ) { if ( ! $plugin_opt['recommended'] ) { continue; } if ( isset( $show_recommended_plugins[ $slug ] ) && $show_recommended_plugins[ $slug ] ) { continue; } $active = $this->check_active( $slug ); if ( ! empty( $active['needs'] ) && ( $active['needs'] == 'deactivate' ) ) { continue; } $bulk_recommended_plugin['url'] = $this->create_action_link( $active['needs'], $slug ); if ( $active['needs'] !== 'install' && $active['status'] ) { $bulk_recommended_plugin['class'] = 'active'; } else { $bulk_recommended_plugin['class'] = ''; } switch ( $active['needs'] ) { case 'install': $bulk_recommended_plugin['button_class'] = 'install-now button'; $bulk_recommended_plugin['button_label'] = $install_button_label; break; case 'activate': $bulk_recommended_plugin['button_class'] = 'activate-now button button-primary'; $bulk_recommended_plugin['button_label'] = $activate_button_label; break; case 'deactivate': $bulk_recommended_plugin['button_class'] = 'deactivate-now button'; $bulk_recommended_plugin['button_label'] = $deactivate_button_label; break; } $info = $this->call_plugin_api( $slug ); $bulk_recommended_plugin['id'] = $slug; $bulk_recommended_plugin['plugin_slug'] = $slug; if ( ! empty( $plugin_opt['description'] ) ) { $bulk_recommended_plugin['description'] = $plugin_opt['description']; } else { $bulk_recommended_plugin['description'] = $info->short_description; } $bulk_recommended_plugin['title'] = $info->name; $customize_plugins[] = $bulk_recommended_plugin; }// End foreach(). $json['recommended_plugins'] = $customize_plugins; $json['plugin_text'] = $this->plugin_text; $json['dismiss_button'] = $this->dismiss_button; return $json; } /** * Outputs the structure for the customizer control * * @since 1.0.0 * @access public * @return void */ protected function render_template() { ?> <# if( data.recommended_plugins.length > 0 ){ #>
{{ data.recommended_plugins[action].title }}