compatibility
1 year ago
class-astra-sites-elementor-images.php
6 years ago
class-astra-sites-elementor-pages.php
2 years ago
class-astra-sites-error-handler.php
2 years ago
class-astra-sites-file-system.php
2 years ago
class-astra-sites-importer-log.php
2 years ago
class-astra-sites-importer.php
1 year ago
class-astra-sites-nps-notice.php
1 year ago
class-astra-sites-page.php
1 year ago
class-astra-sites-update.php
1 year ago
class-astra-sites-utils.php
2 years ago
class-astra-sites-white-label.php
2 years ago
class-astra-sites-wp-cli.php
2 years ago
class-astra-sites.php
1 year ago
functions.php
2 years ago
class-astra-sites-white-label.php
329 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Astra Sites White Label |
| 4 | * |
| 5 | * @package Astra Sites |
| 6 | * @since 1.0.12 |
| 7 | */ |
| 8 | |
| 9 | if ( ! class_exists( 'Astra_Sites_White_Label' ) ) : |
| 10 | |
| 11 | /** |
| 12 | * Astra_Sites_White_Label |
| 13 | * |
| 14 | * @since 1.0.12 |
| 15 | */ |
| 16 | class Astra_Sites_White_Label { |
| 17 | |
| 18 | /** |
| 19 | * Instance |
| 20 | * |
| 21 | * @since 1.0.12 |
| 22 | * |
| 23 | * @var object Class Object. |
| 24 | * @access private |
| 25 | */ |
| 26 | private static $instance; |
| 27 | |
| 28 | /** |
| 29 | * Member Variable |
| 30 | * |
| 31 | * @since 1.0.12 |
| 32 | * |
| 33 | * @var array branding |
| 34 | * @access private |
| 35 | */ |
| 36 | private static $branding; |
| 37 | |
| 38 | /** |
| 39 | * Settings |
| 40 | * |
| 41 | * @since 1.2.11 |
| 42 | * |
| 43 | * @var array settings |
| 44 | * |
| 45 | * @access private |
| 46 | */ |
| 47 | private $settings; |
| 48 | |
| 49 | /** |
| 50 | * Initiator |
| 51 | * |
| 52 | * @since 1.0.12 |
| 53 | * |
| 54 | * @return object initialized object of class. |
| 55 | */ |
| 56 | public static function get_instance() { |
| 57 | if ( ! isset( self::$instance ) ) { |
| 58 | self::$instance = new self(); |
| 59 | } |
| 60 | return self::$instance; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Constructor |
| 65 | * |
| 66 | * @since 1.0.12 |
| 67 | */ |
| 68 | public function __construct() { |
| 69 | add_filter( 'all_plugins', array( $this, 'plugins_page' ) ); |
| 70 | add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' ); |
| 71 | add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_label_form' ); |
| 72 | add_filter( 'astra_sites_menu_page_title', array( $this, 'get_white_label_name' ) ); |
| 73 | add_filter( 'astra_sites_page_title', array( $this, 'get_white_label_name' ) ); |
| 74 | |
| 75 | // Update Astra's admin top level menu position. |
| 76 | add_filter( 'astra_menu_priority', array( $this, 'update_admin_menu_position' ) ); |
| 77 | |
| 78 | // Display the link with the plugin meta. |
| 79 | if ( is_admin() ) { |
| 80 | add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 ); |
| 81 | } |
| 82 | |
| 83 | add_filter( 'gutenberg_templates_localize_vars', array( $this, 'add_white_label_name' ) ); |
| 84 | |
| 85 | add_filter( 'ast_block_templates_white_label', array( $this, 'is_white_labeled' ) ); |
| 86 | add_filter( 'ast_block_templates_white_label_name', array( $this, 'get_white_label' ) ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Update Astra's menu priority to show after Dashboard menu. |
| 91 | * |
| 92 | * @param int $menu_priority top level menu priority. |
| 93 | * @since 3.1.22 |
| 94 | */ |
| 95 | public function update_admin_menu_position( $menu_priority ) { |
| 96 | return 2.1; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Add White Label data |
| 101 | * |
| 102 | * @param array $args White label. |
| 103 | * @since 2.6.0 |
| 104 | */ |
| 105 | public function add_white_label_name( $args = array() ) { |
| 106 | $args['white_label_name'] = $this->get_white_label(); |
| 107 | return $args; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * White labels the plugins page. |
| 112 | * |
| 113 | * @since 1.0.12 |
| 114 | * |
| 115 | * @param array $plugins Plugins Array. |
| 116 | * @return array |
| 117 | */ |
| 118 | public function plugins_page( $plugins ) { |
| 119 | |
| 120 | if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) { |
| 121 | return $plugins; |
| 122 | } |
| 123 | |
| 124 | if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) { |
| 125 | return $plugins; |
| 126 | } |
| 127 | |
| 128 | // Set White Labels. |
| 129 | $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' ); |
| 130 | $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' ); |
| 131 | $author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' ); |
| 132 | $author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' ); |
| 133 | |
| 134 | if ( ! empty( $name ) ) { |
| 135 | $plugins[ ASTRA_SITES_BASE ]['Name'] = $name; |
| 136 | |
| 137 | // Remove Plugin URI if Agency White Label name is set. |
| 138 | $plugins[ ASTRA_SITES_BASE ]['PluginURI'] = ''; |
| 139 | } |
| 140 | |
| 141 | if ( ! empty( $description ) ) { |
| 142 | $plugins[ ASTRA_SITES_BASE ]['Description'] = $description; |
| 143 | } |
| 144 | |
| 145 | if ( ! empty( $author ) ) { |
| 146 | $plugins[ ASTRA_SITES_BASE ]['Author'] = $author; |
| 147 | } |
| 148 | |
| 149 | if ( ! empty( $author_uri ) ) { |
| 150 | $plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri; |
| 151 | } |
| 152 | |
| 153 | return $plugins; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Get value of single key from option array. |
| 158 | * |
| 159 | * @since 2.0.0. |
| 160 | * @param string $type Option type. |
| 161 | * @param string $key Option key. |
| 162 | * @param string $default Default value if key not found. |
| 163 | * @return mixed Return stored option value. |
| 164 | */ |
| 165 | public static function get_option( $type = '', $key = '', $default = null ) { |
| 166 | |
| 167 | if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_white_label' ) ) { |
| 168 | return $default; |
| 169 | } |
| 170 | |
| 171 | $value = Astra_Ext_White_Label_Markup::get_white_label( $type, $key ); |
| 172 | if ( ! empty( $value ) ) { |
| 173 | return $value; |
| 174 | } |
| 175 | |
| 176 | return $default; |
| 177 | |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Remove a "view details" link from the plugin list table |
| 182 | * |
| 183 | * @since 1.0.12 |
| 184 | * |
| 185 | * @param array $plugin_meta List of links. |
| 186 | * @param string $plugin_file Relative path to the main plugin file from the plugins directory. |
| 187 | * @param array $plugin_data Data from the plugin headers. |
| 188 | * @return array |
| 189 | */ |
| 190 | public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) { |
| 191 | |
| 192 | if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) { |
| 193 | return $plugin_meta; |
| 194 | } |
| 195 | |
| 196 | // Set White Labels. |
| 197 | if ( ASTRA_SITES_BASE === $plugin_file ) { |
| 198 | |
| 199 | $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' ); |
| 200 | $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' ); |
| 201 | |
| 202 | // Remove Plugin URI if Agency White Label name is set. |
| 203 | if ( ! empty( $name ) ) { |
| 204 | unset( $plugin_meta[2] ); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return $plugin_meta; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Add White Label setting's |
| 213 | * |
| 214 | * @since 1.0.12 |
| 215 | * |
| 216 | * @param array $settings White label setting. |
| 217 | * @return array |
| 218 | */ |
| 219 | public static function settings( $settings = array() ) { |
| 220 | |
| 221 | $settings['astra-sites'] = array( |
| 222 | 'name' => '', |
| 223 | 'description' => '', |
| 224 | ); |
| 225 | |
| 226 | return $settings; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Add White Label form |
| 231 | * |
| 232 | * @since 1.0.12 |
| 233 | * |
| 234 | * @param array $settings White label setting. |
| 235 | * @return void |
| 236 | */ |
| 237 | public static function add_white_label_form( $settings = array() ) { |
| 238 | |
| 239 | /* translators: %1$s product name */ |
| 240 | $plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME ); |
| 241 | |
| 242 | require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php'; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Page Title |
| 247 | * |
| 248 | * @since 1.0.12 |
| 249 | * |
| 250 | * @param string $title Page Title. |
| 251 | * @return string Filtered Page Title. |
| 252 | */ |
| 253 | public function get_white_label_name( $title = '' ) { |
| 254 | if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) { |
| 255 | $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' ); |
| 256 | if ( ! empty( $astra_sites_name ) ) { |
| 257 | return Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' ); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | return ASTRA_SITES_NAME; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * White Label Link |
| 266 | * |
| 267 | * @since 2.0.0 |
| 268 | * |
| 269 | * @param string $link Default link. |
| 270 | * @return string Filtered Page Title. |
| 271 | */ |
| 272 | public function get_white_label_link( $link = '' ) { |
| 273 | if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) { |
| 274 | $white_label_link = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'licence' ); |
| 275 | if ( ! empty( $white_label_link ) ) { |
| 276 | return $white_label_link; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return $link; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Is Astra sites White labeled |
| 285 | * |
| 286 | * @since 1.2.13 |
| 287 | * |
| 288 | * @return string |
| 289 | */ |
| 290 | public function is_white_labeled() { |
| 291 | $white_label = $this->get_white_label(); |
| 292 | |
| 293 | if ( empty( $white_label ) ) { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | return true; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Get white label name |
| 302 | * |
| 303 | * @since 2.6.0 |
| 304 | * |
| 305 | * @return string |
| 306 | */ |
| 307 | public function get_white_label() { |
| 308 | if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) { |
| 309 | return ''; |
| 310 | } |
| 311 | |
| 312 | $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' ); |
| 313 | |
| 314 | if ( ! empty( $name ) ) { |
| 315 | return $name; |
| 316 | } |
| 317 | |
| 318 | return ''; |
| 319 | } |
| 320 | |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Kicking this off by calling 'get_instance()' method |
| 325 | */ |
| 326 | Astra_Sites_White_Label::get_instance(); |
| 327 | |
| 328 | endif; |
| 329 |