/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. if ( class_exists( 'Yoast_License_Manager' ) && ! class_exists( "Yoast_Plugin_License_Manager", false ) ) {
  3. class Yoast_Plugin_License_Manager extends Yoast_License_Manager {
  4. /**
  5. * Constructor
  6. *
  7. * @param Yoast_Product $product
  8. */
  9. public function __construct( Yoast_Product $product ) {
  10. parent::__construct( $product );
  11. // Check if plugin is network activated. We should use site(wide) options in that case.
  12. if( is_admin() && is_multisite() ) {
  13. if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
  14. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  15. }
  16. $this->is_network_activated = is_plugin_active_for_network( $product->get_file() );
  17. }
  18. }
  19. /**
  20. * Setup auto updater for plugins
  21. */
  22. public function setup_auto_updater() {
  23. /**
  24. * Filter: 'yoast-license-valid' - Perform action when license is valid or hook returns true.
  25. *
  26. * @api bool $is_valid True if the license is valid.
  27. */
  28. if ( apply_filters( 'yoast-license-valid', $this->license_is_valid() ) ) {
  29. // setup auto updater
  30. require_once( dirname( __FILE__ ) . '/class-update-manager.php' );
  31. require_once( dirname( __FILE__ ) . '/class-plugin-update-manager.php' );
  32. new Yoast_Plugin_Update_Manager( $this->product, $this );
  33. }
  34. }
  35. /**
  36. * Setup hooks
  37. */
  38. public function specific_hooks() {
  39. // deactivate the license remotely on plugin deactivation
  40. register_deactivation_hook( $this->product->get_file(), array( $this, 'deactivate_license' ) );
  41. }
  42. /**
  43. * Show a form where users can enter their license key
  44. * Takes Multisites into account
  45. *
  46. * @param bool $embedded
  47. * @return null
  48. */
  49. public function show_license_form( $embedded = true ) {
  50. // For non-multisites, always show the license form
  51. if( ! is_multisite() ) {
  52. parent::show_license_form( $embedded );
  53. return;
  54. }
  55. // Plugin is network activated
  56. if( $this->is_network_activated ) {
  57. // We're on the network admin
  58. if( is_network_admin() ) {
  59. parent::show_license_form( $embedded );
  60. } else {
  61. // We're not in the network admin area, show a notice
  62. parent::show_license_form_heading();
  63. if ( is_super_admin() ) {
  64. 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>";
  65. } else {
  66. 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>";
  67. }
  68. }
  69. } else {
  70. if( false == is_network_admin() ) {
  71. parent::show_license_form( $embedded );
  72. }
  73. }
  74. }
  75. }
  76. }