is_plugin_active( $slug . '/' . $slug . '.php' ), 'needs' => $needs ); } return array( 'status' => false, 'needs' => 'install' ); } 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; } } public function call_plugin_api( $slug ) { include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); if ( false === ( $call_api = get_transient( 'affluent_plugin_information_transient_' . $slug ) ) ) { $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' => true, 'homepage' => true, 'added' => false, 'last_updated' => false, 'compatibility' => false, 'tested' => false, 'requires' => false, 'downloadlink' => false, 'icons' => true ) ) ); set_transient( 'affluent_plugin_information_transient_' . $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 void */ public function json() { $json = parent::json(); global $affluent_required_actions, $affluent_recommended_plugins; $formatted_array = array(); $affluent_show_required_actions = get_option( "affluent_show_required_actions" ); foreach ( $affluent_required_actions as $key => $affluent_required_action ) { if ( @$affluent_show_required_actions[ $affluent_required_action['id'] ] === false ) { continue; } if ( $affluent_required_action['check'] ) { continue; } $affluent_required_action['index'] = $key + 1; if ( isset($affluent_required_action['plugin_slug']) ) { $active = $this->check_active( $affluent_required_action['plugin_slug'] ); $affluent_required_action['url'] = $this->create_action_link( $active['needs'], $affluent_required_action['plugin_slug'] ); if ( $active['needs'] !== 'install' && $active['status'] ) { $affluent_required_action['class'] = 'active'; }else{ $affluent_required_action['class'] = ''; } switch ( $active['needs'] ) { case 'install': $affluent_required_action['button_class'] = 'install-now button'; $affluent_required_action['button_label'] = __( 'Install', 'affluent' ); break; case 'activate': $affluent_required_action['button_class'] = 'activate-now button button-primary'; $affluent_required_action['button_label'] = __( 'Activate', 'affluent' ); break; case 'deactivate': $affluent_required_action['button_class'] = 'deactivate-now button'; $affluent_required_action['button_label'] = __( 'Deactivate', 'affluent' ); break; } } $formatted_array[] = $affluent_required_action; } $customize_plugins = array(); $affluent_show_recommended_plugins = get_option( "affluent_show_recommended_plugins" ); foreach ( $affluent_recommended_plugins as $slug => $plugin_opt ) { if ( !$plugin_opt['recommended'] ) { continue; } if ( MT_Notify_System::has_plugin( $slug ) ) { continue; } if ( isset($affluent_show_recommended_plugins[$slug]) && $affluent_show_recommended_plugins[$slug] ) { continue; } $active = $this->check_active( $slug ); $affluent_recommended_plugin['url'] = $this->create_action_link( $active['needs'], $slug ); if ( $active['needs'] !== 'install' && $active['status'] ) { $affluent_recommended_plugin['class'] = 'active'; }else{ $affluent_recommended_plugin['class'] = ''; } switch ( $active['needs'] ) { case 'install': $affluent_recommended_plugin['button_class'] = 'install-now button'; $affluent_recommended_plugin['button_label'] = __( 'Install', 'affluent' ); break; case 'activate': $affluent_recommended_plugin['button_class'] = 'activate-now button button-primary'; $affluent_recommended_plugin['button_label'] = __( 'Activate', 'affluent' ); break; case 'deactivate': $affluent_recommended_plugin['button_class'] = 'deactivate-now button'; $affluent_recommended_plugin['button_label'] = __( 'Deactivate', 'affluent' ); break; } $info = $this->call_plugin_api( $slug ); $affluent_recommended_plugin['id'] = $slug; $affluent_recommended_plugin['plugin_slug'] = $slug; $affluent_recommended_plugin['description'] = $info->short_description; $affluent_recommended_plugin['title'] = $affluent_recommended_plugin['button_label'].': '.$info->name; $customize_plugins[] = $affluent_recommended_plugin; } $json['required_actions'] = $formatted_array; $json['recommended_plugins'] = $customize_plugins; $json['total_actions'] = count($affluent_required_actions); $json['social_text'] = $this->social_text; $json['plugin_text'] = $this->plugin_text; $json['facebook'] = $this->facebook; $json['facebook_text'] = __( 'Facebook', 'affluent' ); $json['twitter'] = $this->twitter; $json['twitter_text'] = __( 'Twitter', 'affluent' ); $json['wp_review'] = $this->wp_review; $json['wp_review_text'] = __( 'Review this theme on w.org', 'affluent' ); if ( $this->wp_review ) { $json['theme_slug'] = get_template(); } return $json; } /** * Outputs the Underscore.js template. * * @since 1.0.0 * @access public * @return void */ protected function render_template() { ?>
{{ data.required_actions[action].title }}
{{ data.recommended_plugins[action].title }}
<# if( data.facebook ){ #> {{ data.facebook_text }} <# } #> <# if( data.twitter ){ #> {{ data.twitter_text }} <# } #> <# if( data.wp_review ){ #> {{ data.wp_review_text }} <# } #>
<# }else{ #> <# } #>