| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file that defines the core plugin class |
| 4 |
* |
| 5 |
* A class definition that includes attributes and functions used across both the |
| 6 |
* public-facing side of the site and the admin area. |
| 7 |
* |
| 8 |
* @link https://posimyth.com/ |
| 9 |
* @since 1.0.0 |
| 10 |
* |
| 11 |
* @package Wdesignkit |
| 12 |
* @subpackage Wdesignkit/includes |
| 13 |
*/ |
| 14 |
|
| 15 |
/**Exit if accessed directly.*/ |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
if ( ! class_exists( 'Wdkit_Plugin_Page' ) ) { |
| 21 |
|
| 22 |
/** |
| 23 |
* Wdkit_Plugin_Page |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
*/ |
| 27 |
class Wdkit_Plugin_Page { |
| 28 |
|
| 29 |
/** |
| 30 |
* Singleton instance variable. |
| 31 |
* |
| 32 |
* @var instance|null The single instance of the class. |
| 33 |
*/ |
| 34 |
private static $instance; |
| 35 |
|
| 36 |
/** |
| 37 |
* Singleton instance getter method. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* |
| 41 |
* @return self The single instance of the class. |
| 42 |
*/ |
| 43 |
public static function get_instance() { |
| 44 |
if ( ! isset( self::$instance ) ) { |
| 45 |
self::$instance = new self(); |
| 46 |
} |
| 47 |
|
| 48 |
return self::$instance; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Initializes the core functionalities of the plugin for admin users with 'manage_options' capability. |
| 53 |
* |
| 54 |
* This constructor method checks if the current user is in the WordPress admin dashboard |
| 55 |
* and has the capability to manage options. If these conditions are met, it adds specific |
| 56 |
* filters to enhance the plugin's functionality in the admin area. |
| 57 |
* |
| 58 |
* @since 1.0.0 |
| 59 |
* @access public |
| 60 |
*/ |
| 61 |
public function __construct() { |
| 62 |
|
| 63 |
if ( is_admin() && current_user_can( 'manage_options' ) ) { |
| 64 |
// Add a filter to include a settings link for the plugin in the WordPress plugins page. |
| 65 |
add_filter( 'plugin_action_links_' . WDKIT_PBNAME, array( $this, 'wdkit_settings_pro_link' ) ); |
| 66 |
|
| 67 |
// Add a filter to include additional links/meta for the plugin on the WordPress plugins page. |
| 68 |
add_filter( 'plugin_row_meta', array( $this, 'wdkit_extra_links_plugin_row_meta' ), 10, 2 ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Generates additional links for the plugin on the plugins page. |
| 74 |
* |
| 75 |
* This function modifies the plugin's action links by adding custom links for 'Settings' and 'Need Help?' |
| 76 |
* to the existing list of links displayed on the WordPress plugins page. |
| 77 |
* |
| 78 |
* @since 1.0.0 |
| 79 |
* @access public |
| 80 |
* |
| 81 |
* @param string[] $links An array containing the existing links for the plugin. |
| 82 |
* @return string[] An updated array with additional custom links. |
| 83 |
*/ |
| 84 |
public function wdkit_settings_pro_link( $links ) { |
| 85 |
|
| 86 |
$settings = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=wdesign-kit#/login' ), __( 'Settings', 'wdesignkit' ) ); |
| 87 |
$need_help = sprintf( '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', esc_url( 'https://wdesignkit.com/' ), __( 'Need Help?', 'wdesignkit' ) ); |
| 88 |
|
| 89 |
$links = (array) $links; |
| 90 |
$links[] = $settings; |
| 91 |
$links[] = $need_help; |
| 92 |
|
| 93 |
return $links; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Adds extra links/meta to the plugin's row on the WordPress plugins page. |
| 98 |
* |
| 99 |
* @since 1.0.0 |
| 100 |
* @access public |
| 101 |
* |
| 102 |
* @param string $plugin_meta return full array. |
| 103 |
* @param string $plugin_file check path. |
| 104 |
* @return array An updated array containing additional custom links/meta. |
| 105 |
*/ |
| 106 |
public function wdkit_extra_links_plugin_row_meta( $plugin_meta = array(), $plugin_file = '' ) { |
| 107 |
|
| 108 |
if ( strpos( $plugin_file, WDKIT_PBNAME ) !== false ) { |
| 109 |
$new_links = array( |
| 110 |
'join-community' => '<a href="' . esc_url( 'https://www.facebook.com/groups/wdesignkit' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Join Community', 'wdesignkit' ) . '</a>', |
| 111 |
'whats-new' => '<a href="' . esc_url( 'https://roadmap.wdesignkit.com/roadmap' ) . '" target="_blank" rel="noopener noreferrer" style="color: orange;">' . esc_html__( 'What\'s New?', 'wdesignkit' ) . '</a>', |
| 112 |
'req-feature' => '<a href="' . esc_url( 'https://roadmap.wdesignkit.com/boards/feature-requests' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Request Feature', 'wdesignkit' ) . '</a>', |
| 113 |
); |
| 114 |
|
| 115 |
$plugin_meta = array_merge( $plugin_meta, $new_links ); |
| 116 |
} |
| 117 |
|
| 118 |
return $plugin_meta; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
Wdkit_Plugin_Page::get_instance(); |
| 123 |
} |
| 124 |
|