PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/vendor/yoast/license-manager/class-plugin-license-manager.php

https://bitbucket.org/carloskikea/helpet
PHP | 95 lines | 46 code | 19 blank | 30 comment | 15 complexity | ff4fdc3feb24b32231e6c54e31d14cf6 MD5 | raw file
 1<?php
 2
 3if ( class_exists( 'Yoast_License_Manager' ) && ! class_exists( "Yoast_Plugin_License_Manager", false ) ) {
 4
 5	class Yoast_Plugin_License_Manager extends Yoast_License_Manager {
 6
 7		/**
 8		 * Constructor
 9		 *
10		 * @param Yoast_Product $product
11		 */
12		public function __construct( Yoast_Product $product ) {
13
14			parent::__construct( $product );
15
16			// Check if plugin is network activated. We should use site(wide) options in that case.
17			if( is_admin() && is_multisite() ) {
18
19				if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
20					require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
21				}
22
23				$this->is_network_activated = is_plugin_active_for_network( $product->get_file() );
24			}
25		}
26
27		/**
28		 * Setup auto updater for plugins
29		 */
30		public function setup_auto_updater() {
31			/**
32			 * Filter: 'yoast-license-valid' - Perform action when license is valid or hook returns true.
33			 *
34			 * @api bool $is_valid True if the license is valid.
35			 */
36			if ( apply_filters( 'yoast-license-valid', $this->license_is_valid() ) ) {
37				// setup auto updater
38				require_once( dirname( __FILE__ ) . '/class-update-manager.php' );
39				require_once( dirname( __FILE__ ) . '/class-plugin-update-manager.php' );
40				new Yoast_Plugin_Update_Manager( $this->product, $this );
41			}
42		}
43
44		/**
45		 * Setup hooks
46		 */
47		public function specific_hooks() {
48
49			// deactivate the license remotely on plugin deactivation
50			register_deactivation_hook( $this->product->get_file(), array( $this, 'deactivate_license' ) );
51		}
52
53        /**
54         * Show a form where users can enter their license key
55         * Takes Multisites into account
56         *
57         * @param bool $embedded
58         * @return null
59         */
60        public function show_license_form( $embedded = true ) {
61
62	        // For non-multisites, always show the license form
63	        if( ! is_multisite() ) {
64		       parent::show_license_form( $embedded );
65		       return;
66	        }
67
68	        // Plugin is network activated
69	        if( $this->is_network_activated ) {
70
71		        // We're on the network admin
72	            if( is_network_admin() ) {
73		            parent::show_license_form( $embedded );
74	            } else {
75		            // We're not in the network admin area, show a notice
76		            parent::show_license_form_heading();
77		            if ( is_super_admin() ) {
78			            echo "<p>" . sprintf( __( '%s is network activated, you can manage your license in the <a href="%s">network admin license page</a>.', $this->product->get_text_domain() ), $this->product->get_item_name(), $this->product->get_license_page_url() ) . "</p>";
79		            } else {
80			            echo "<p>" . sprintf( __( '%s is network activated, please contact your site administrator to manage the license.', $this->product->get_text_domain() ), $this->product->get_item_name() ) . "</p>";
81		            }
82
83	            }
84
85		    }  else {
86
87		        if( false == is_network_admin() ) {
88					parent::show_license_form( $embedded );
89			    }
90
91	        }
92        }
93	}
94
95}