set_text_domain( $text_domain ); $this->collect_installed_plugins(); $this->collect_activated_plugins(); add_action('admin_head', [$this, 'enqueue_scripts']); return $this; } /** * Set the section title. * * @param string $title The title of the section. * @return $this The current object instance. * * @since 1.0.0 */ public function set_section_title( $title ){ $this->section_title = $title; return $this; } /** * Sets the description for the section. * * @param mixed $description The description for the section. * @return $this * * @since 1.0.0 */ public function set_section_description( $description ){ $this->section_description = $description; return $this; } /** * Sets the number of items per row. * * @param int $items The number of items per row. * @return $this The current object instance. * * @since 1.0.0 */ public function set_items_per_row( $items ){ $this->items_per_row = $items; return $this; } /** * Set the text domain for the object. * * @param mixed $val The value to set as the text domain. * @return $this The current object instance. * * @since 1.0.0 */ protected function set_text_domain( $val ) { $this->text_domain = $val; return $this; } /** * Sets the submenu name. * * @param string $submenu_name The name of the submenu. * @return $this The current instance of the class. * * @since 1.0.0 */ public function set_submenu_name( $submenu_name ){ $this->submenu_name = $submenu_name; return $this; } /** * Set the parent menu slug. * * @param string $slug The slug of the parent menu. * @return $this The current object. */ public function set_parent_menu_slug( $slug ) { $this->parent_menu_slug = $slug; return $this; } /** * Sets the menu slug for the object. * * @param string $slug The slug to set for the menu. * @return $this Returns the current object. * * @since 1.0.0 */ public function set_menu_slug( $slug ) { $this->menu_slug = $slug; return $this; } /** * Set the plugins for the object. * * @param array $plugins An array of plugins. * @return $this The current instance. * * @since 1.0.0 */ public function set_plugins( $plugins = [] ) { $this->plugins = $plugins; return $this; } /** * Registers a menu in the WordPress admin dashboard. * * @return void * * @since 1.0.0 */ protected function register_menu() { add_submenu_page( $this->parent_menu_slug, $this->submenu_name, '' . $this->submenu_name . '', 'manage_options', $this->text_domain . $this->menu_slug, [$this, 'wpmet_apps_renderer'] ); } /** * Generates the menus. * * @return void * * @since 1.0.0 */ public function generate_menus() { if( !empty($this->parent_menu_slug) ) { $this->register_menu(); } } /** * Admin menu registration hook. * * @return void * * @since 1.0.0 */ public function call() { add_action('admin_menu', [$this, 'generate_menus'], 99999); } /** * Activation URL * * @since 1.0.0 * @param string $pluginName The name of the plugin. * @return string */ public function activation_url( $pluginName ) { return wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $pluginName, 'plugin_status' => 'all', 'paged' => '1&s', ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $pluginName ); } /** * Installation URL * * @since 1.0.0 * @param string $pluginName The name of the plugin. * @return string */ public function installation_url( $pluginName ) { $action = 'install-plugin'; $pluginSlug = $this->get_plugin_slug( $pluginName ); return wp_nonce_url( add_query_arg( array( 'action' => $action, 'plugin' => $pluginSlug ), admin_url( 'update.php' ) ), $action . '_' . $pluginSlug ); } /** * Get plugin slug * * @since 1.0.0 * @param string $name The name of the plugin. * @return string */ public function get_plugin_slug( $name ) { $split = explode( '/', $name ); return isset( $split[0] ) ? $split[0] : null; } /** * Activated URL * * @since 1.0.0 * @param string $pluginName The name of the plugin. * @return string */ public function activated_url( $pluginName ) { return add_query_arg( array( 'page' => $this->get_plugin_slug( $pluginName ), ), admin_url( 'admin.php' ) ); } /** * Collect installed plugins * * @since 1.0.0 * @return void */ private function collect_installed_plugins() { if( !function_exists('get_plugins') ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } foreach ( get_plugins() as $key => $plugin ) { array_push( $this->installed_plugins, $key ); } } /** * Collect activated plugins * * @since 1.0.0 * @return void */ private function collect_activated_plugins() { foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) { array_push( $this->activated_plugins, $plugin ); } } /** * Check installed plugin * * @since 1.0.0 * @param string $name The name of the plugin. * @return bool */ public function check_installed_plugin( $name ) { return in_array( $name, $this->installed_plugins ); } /** * Check activated plugin * * @since 1.0.0 * @param string $name The name of the plugin. * @return bool */ public function check_activated_plugin( $name ) { return in_array( $name, $this->activated_plugins ); } /** * Get plugin status * * @since 1.0.0 * @param string $name The name of the plugin. * @return array */ public function get_plugin_status( $name ) { $data = [ "url" => "", "activation_url" => "", "installation_url" => "", "title" => "", "status" => "", ]; if ( $this->check_installed_plugin( $name ) ) { if ( $this->check_activated_plugin( $name ) ) { $data['title'] = __( 'Activated', 'metform' ); $data['status'] = "activated"; } else { $data['title'] = __( 'Activate Now', 'metform' ); $data['status'] = 'installed'; $data['activation_url'] = $this->activation_url( $name ); } } else { $data['title'] = __( 'Install Now', 'metform' ); $data['status'] = 'not_installed'; $data['installation_url'] = $this->installation_url( $name ); $data['activation_url'] = $this->activation_url( $name ); } return $data; } /** * Display the Wpmet apps section. * * @return void * * @since 1.0.0 */ public function wpmet_apps_renderer() { ?>

section_title); ?>

section_description); ?>

plugins as $key => $plugin ): $img_url = isset($plugin['icon']) ? $plugin['icon'] : '#'; $plugin_name = isset($plugin['name']) ? $plugin['name'] : ''; $plugin_desc = isset($plugin['desc']) ? $plugin['desc'] : ''; $plugin_docs = isset($plugin['docs']) ? $plugin['docs'] : ''; ?>