attr.php
147 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Libs\Framework; |
| 3 | |
| 4 | use ElementsKit_Lite\Libs\Framework\Classes\Utils; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; |
| 7 | |
| 8 | class Attr { |
| 9 | |
| 10 | use \ElementsKit_Lite\Traits\Singleton; |
| 11 | |
| 12 | public $utils; |
| 13 | |
| 14 | public static function get_dir() { |
| 15 | return \ElementsKit_Lite::lib_dir() . 'framework/'; |
| 16 | } |
| 17 | |
| 18 | public static function get_url() { |
| 19 | return \ElementsKit_Lite::lib_url() . 'framework/'; |
| 20 | } |
| 21 | |
| 22 | public static function key() { |
| 23 | return 'elementskit'; |
| 24 | } |
| 25 | |
| 26 | public function __construct() { |
| 27 | $this->utils = Classes\Utils::instance(); |
| 28 | new Classes\Ajax(); |
| 29 | |
| 30 | // register admin menus |
| 31 | add_action( 'admin_menu', array( $this, 'register_settings_menus' ) ); |
| 32 | // add_action('admin_menu', [$this, 'register_support_menu'], 999); |
| 33 | |
| 34 | // register js/ css |
| 35 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 36 | |
| 37 | // whitelist styles |
| 38 | add_filter( 'mailpoet_conflict_resolver_whitelist_style', array( $this, 'whitelisted_styles' ) ); |
| 39 | |
| 40 | add_action( 'elementskit-lite/pro_awareness/before_grid_contents', array( $this, 'user_consent_for_banner' ) ); |
| 41 | } |
| 42 | |
| 43 | public function whitelisted_styles( $styles ) { |
| 44 | $styles[] = 'admin-global.css'; |
| 45 | return $styles; |
| 46 | } |
| 47 | |
| 48 | public function include_files() { |
| 49 | } |
| 50 | |
| 51 | public function enqueue_scripts() { |
| 52 | wp_register_style( 'elementskit-admin-global', \ElementsKit_Lite::lib_url() . 'framework/assets/css/admin-global.css', false, \ElementsKit_Lite::version() ); |
| 53 | wp_enqueue_style( 'elementskit-admin-global' ); |
| 54 | add_filter('admin_footer_text', [$this, 'elementskit_admin_footer_text']); |
| 55 | } |
| 56 | |
| 57 | public function register_settings_menus() { |
| 58 | |
| 59 | // dashboard, main menu |
| 60 | add_menu_page( |
| 61 | esc_html__( 'ElementsKit Settings', 'elementskit-lite' ), |
| 62 | 'ElementsKit', // esc_html__( 'ElementsKit', 'elementskit-lite' ), |
| 63 | 'manage_options', |
| 64 | self::key(), |
| 65 | array( $this, 'register_settings_contents__settings' ), |
| 66 | self::get_url() . 'assets/images/ekit_icon.svg', |
| 67 | '58.6' |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | public function elementskit_admin_footer_text($text) { |
| 72 | // Only show on ElementsKit admin pages |
| 73 | if ( ! $this->is_elementskit_page() ) { |
| 74 | return $text; |
| 75 | } |
| 76 | |
| 77 | $plugin_name = '<strong>' . esc_html__( 'ElementsKit', 'elementskit-lite' ) . '</strong>'; |
| 78 | $review_url = esc_url( 'https://wordpress.org/support/plugin/elementskit-lite/reviews/'); |
| 79 | |
| 80 | $text = sprintf( |
| 81 | '<span class="elementskit-footer-text"><i>%1$s</i></span>', |
| 82 | sprintf( |
| 83 | /* translators: 1: Plugin name, 2: Review URL */ |
| 84 | __( 'Enjoying %1$s? Please consider leaving us a <a href="%2$s" target="_blank" rel="noopener noreferrer">� |
| 85 | � |
| 86 | � |
| 87 | � |
| 88 | � |
| 89 | </a> review. Your support means a lot to our team!', 'elementskit-lite' ), |
| 90 | $plugin_name, |
| 91 | $review_url |
| 92 | ) |
| 93 | ); |
| 94 | return $text; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Check if current page is an ElementsKit admin page |
| 99 | * |
| 100 | * @return bool |
| 101 | */ |
| 102 | private function is_elementskit_page() { |
| 103 | $current_screen = get_current_screen(); |
| 104 | |
| 105 | if ( ! $current_screen ) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | // List of allowed pages (from ?page parameter) |
| 110 | $allowed_pages = array( |
| 111 | 'elementskit', |
| 112 | 'elementskit-license', |
| 113 | 'forms', |
| 114 | 'elementskit-lite_wpmet_plugins', |
| 115 | 'elementskit-lite_get_help', |
| 116 | ); |
| 117 | |
| 118 | // List of allowed post types (from ?post_type parameter) |
| 119 | $allowed_post_types = array( |
| 120 | 'elementskit_template', |
| 121 | 'elementskit_widget', |
| 122 | ); |
| 123 | |
| 124 | // Check by post_type (for custom post type listings) |
| 125 | if ( ! empty( $current_screen->post_type ) && in_array( $current_screen->post_type, $allowed_post_types, true ) ) { |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | // Check by page parameter (for admin pages) |
| 130 | $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; |
| 131 | if ( $page && in_array( $page, $allowed_pages, true ) ) { |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | public function register_settings_contents__settings() { |
| 139 | include self::get_dir() . 'views/init.php'; |
| 140 | } |
| 141 | |
| 142 | public function user_consent_for_banner() { |
| 143 | include self::get_dir() . 'views/layout-user-consent-for-banner.php'; |
| 144 | } |
| 145 | |
| 146 | } |
| 147 |