| 1 |
<?php |
| 2 |
|
| 3 |
namespace Pronamic\WordPress\PronamicClient; |
| 4 |
|
| 5 |
class GravityFormsModule { |
| 6 |
/** |
| 7 |
* Instance of this class. |
| 8 |
* |
| 9 |
* @var GravityFormsModule |
| 10 |
*/ |
| 11 |
protected static $instance = null; |
| 12 |
|
| 13 |
/** |
| 14 |
* Plugin |
| 15 |
* |
| 16 |
* @var Plugin |
| 17 |
*/ |
| 18 |
private $plugin; |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructs and initialize Gravity Forms module. |
| 22 |
* |
| 23 |
* @param Plugin $plugin |
| 24 |
*/ |
| 25 |
private function __construct( Plugin $plugin ) { |
| 26 |
$this->plugin = $plugin; |
| 27 |
|
| 28 |
$this->setup(); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Setup. |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
private function setup() { |
| 37 |
if ( ! \is_admin() ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
\add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Plugins loaded. |
| 46 |
* |
| 47 |
* @link https://developer.wordpress.org/reference/hooks/plugins_loaded/ |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function plugins_loaded() { |
| 51 |
if ( ! \class_exists( '\GFForms' ) ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
\add_action( 'current_screen', [ $this, 'current_screen' ] ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Current screen. |
| 60 |
* |
| 61 |
* @link https://developer.wordpress.org/reference/hooks/current_screen/ |
| 62 |
* @param \WP_Screen $screen Screen. |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function current_screen( $screen ) { |
| 66 |
if ( 'forms_page_gf_settings' !== $screen->id ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$user = \wp_get_current_user(); |
| 71 |
|
| 72 |
if ( 'pronamic' === $user->user_login ) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
\add_action( 'admin_print_styles-' . $screen->id, [ $this, 'admin_print_styles' ] ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Admin print styles. |
| 81 |
* |
| 82 |
* @link https://developer.wordpress.org/reference/hooks/admin_print_styles-hook_suffix/ |
| 83 |
* @link https://developer.wordpress.org/reference/hooks/admin_print_styles/ |
| 84 |
* @return void |
| 85 |
*/ |
| 86 |
public function admin_print_styles() { |
| 87 |
?> |
| 88 |
<style type="text/css">#gform-settings-section-section_license_key_details { display: none; }</style> |
| 89 |
<?php |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Return an instance of this class. |
| 94 |
* |
| 95 |
* @return object A single instance of this class. |
| 96 |
*/ |
| 97 |
public static function get_instance( $plugin = false ) { |
| 98 |
// If the single instance hasn't been set, set it now. |
| 99 |
if ( null === self::$instance ) { |
| 100 |
self::$instance = new self( $plugin ); |
| 101 |
} |
| 102 |
|
| 103 |
return self::$instance; |
| 104 |
} |
| 105 |
} |
| 106 |
|