check_plugin_state( $slug ); if ( empty( $slug ) ) { return ''; } $plugin_name = ''; if ( ! empty( $settings ) && array_key_exists( 'plugin_name', $settings ) ) { $plugin_name = $settings['plugin_name']; } $additional = ''; if ( $state === 'deactivate' ) { $additional = ' action_button active'; } $button .= '
'; $plugin_link_suffix = self::get_plugin_path( $slug ); $nonce = add_query_arg( array( 'action' => 'activate', 'plugin' => rawurlencode( $plugin_link_suffix ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_link_suffix ), ), network_admin_url( 'plugins.php' ) ); switch ( $state ) { case 'install': $button .= '' . __( 'Install and activate', 'bloghash' ) . ' ' . esc_html( $plugin_name ) . ''; break; case 'activate': $button .= '' . esc_html__( 'Activate', 'bloghash' ) . ' ' . esc_html( $plugin_name ) . ''; break; case 'deactivate': $nonce = add_query_arg( array( 'action' => 'deactivate', 'plugin' => rawurlencode( $plugin_link_suffix ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $plugin_link_suffix ), ), network_admin_url( 'plugins.php' ) ); $button .= '' . esc_html__( 'Deactivate', 'bloghash' ) . ' ' . esc_html( $plugin_name ) . ''; break; case 'enable_cpt': $url = admin_url( 'admin.php?page=jetpack#/settings' ); $button .= '' . esc_html__( 'Activate', 'bloghash' ) . ' ' . esc_html__( 'Jetpack Portfolio', 'bloghash' ) . ''; break; }// End switch(). $button .= '
'; return $button; } /** * Check plugin state. * * @param string $slug plugin slug. * * @return bool */ public function check_plugin_state( $slug ) { $plugin_link_suffix = self::get_plugin_path( $slug ); if ( is_file( ABSPATH . 'wp-content/plugins/' . $plugin_link_suffix ) ) { $needs = is_plugin_active( $plugin_link_suffix ) ? 'deactivate' : 'activate'; if ( $needs === 'deactivate' && ! post_type_exists( 'portfolio' ) && $slug === 'jetpack' ) { return 'enable_cpt'; } return $needs; } else { return 'install'; } } /** * Enqueue Function. */ public function enqueue_scripts() { wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'updates' ); wp_enqueue_script( 'bloghash-plugin-install-helper', get_template_directory_uri() . '/inc/customizer/ui/plugin-install-helper/helper-script.js', array( 'jquery' ), BLOGHASH_THEME_VERSION, true ); wp_localize_script( 'bloghash-plugin-install-helper', 'bloghash_plugin_helper', array( 'activating' => esc_html__( 'Activating ', 'bloghash' ), ) ); wp_localize_script( 'bloghash-plugin-install-helper', 'pagenow', array( 'import' ) ); } }