handler_actions(); add_action( 'admin_head', array( $self, 'manager_styles' ) ); add_action( 'admin_menu', array( $self, 'add_menu_page' ) ); add_action( 'plugin_action_links_powerkit/powerkit.php', array( $self, 'action_links' ) ); } ); } /** * Register a callback for our specific plugin's actions * * @param array $actions An array of plugin action links. */ public function action_links( $actions ) { $actions[] = sprintf( '%s', powerkit_get_page_url( $this->menu_slug ), esc_html__( 'Settings', 'powerkit' ) ); return $actions; } /** * Add menu page */ public function add_menu_page() { $svg = ''; $svg = 'data:image/svg+xml;base64,' . base64_encode( $svg ); add_menu_page( esc_html__( 'Powerkit', 'powerkit' ), esc_html__( 'Powerkit', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->menu_slug ), array( $this, 'settings_page' ), $svg ); } /** * Manager styles */ public function manager_styles() { ?> menu_slug, 'admin' ); // Check wpnonce. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok. return; } // Filter modules. if ( isset( $_REQUEST['filter'] ) ) { // Input var ok. $filter = sanitize_key( $_REQUEST['filter'] ); // Input var ok. } // Output Message. if ( $this->msg ) { echo wp_kses( $this->msg, 'post' ); } ?>

wp_create_nonce(), 'filter' => 'active', ), $page_link ); $inactive_link = add_query_arg( array( '_wpnonce' => wp_create_nonce(), 'filter' => 'inactive', ), $page_link ); $num_modules = 0; $num_active_modules = 0; $num_inactive_modules = 0; if ( $modules ) { foreach ( $modules as $key => $module ) { if ( ! $module['public'] ) { continue; } $num_modules++; if ( powerkit_module_enabled( $module['slug'] ) ) { $num_active_modules++; } else { $num_inactive_modules++; } } } ?>
$module ) { // Public module. if ( ! $module['public'] ) { continue; } // Check module enabled. $module_enabled = powerkit_module_enabled( $module['slug'] ); // Filter list. if ( isset( $filter ) ) { if ( 'active' === $filter && ! $module_enabled ) { continue; } if ( 'inactive' === $filter && $module_enabled ) { continue; } } $activate_link = add_query_arg( array( '_wpnonce' => wp_create_nonce(), 'slug' => $module['slug'], 'action' => 'activate', ), $page_link ); $deactivate_link = add_query_arg( array( '_wpnonce' => wp_create_nonce(), 'slug' => $module['slug'], 'action' => 'deactivate', ), $page_link ); $counter++; ?>

set_module_state( $slug, 1 ); } elseif ( 'deactivate-selected' === $action ) { $this->set_module_state( $slug, 0 ); } } } if ( ! isset( $_REQUEST['slug'] ) ) { // Input var ok. return; } $slug = sanitize_key( $_REQUEST['slug'] ); // Input var ok. // Activate module. if ( 'activate' === $action && $slug ) { $this->set_module_state( $slug, 1 ); } // Deactivate module. if ( 'deactivate' === $action && $slug ) { $this->set_module_state( $slug, 0 ); } } /** * Set state module. * * @param string $slug The slug module. * @param bool $state The state module. */ public function set_module_state( $slug, $state ) { update_option( sprintf( 'powerkit_enabled_%s', $slug ), $state ); if ( $state ) { $this->msg = sprintf( '

%s

', esc_html__( 'Module activated.', 'powerkit' ) ); } else { $this->msg = sprintf( '

%s

', esc_html__( 'Module deactivated.', 'powerkit' ) ); } } } new Admin_Powerkit_Manager();