28 const ID =
'gk_foundation';
93 $this->_plugin_activation_handler->register_hooks( $plugin_file );
95 $this->_registered_plugins[
'foundation_source'] = $plugin_file;
98 'gk/foundation/get-instance',
99 function ( $passed_instance ) use ( $plugin_file ) {
100 if ( ! $passed_instance || ! defined( get_class( $passed_instance ) .
'::VERSION' ) || ! is_callable( [ $passed_instance,
'get_registered_plugins' ] ) ) {
104 $instance_to_return = version_compare( $passed_instance::VERSION, self::VERSION,
'<' ) ? $this : $passed_instance;
115 $force_standalone_instance = apply_filters(
'gk/foundation/force-standalone-foundation-instance',
true );
117 if ( $force_standalone_instance ) {
118 $plugin_data = CoreHelpers::get_plugin_data( $plugin_file );
120 if (
'gk-foundation' ===
Arr::get( $plugin_data,
'TextDomain' ) ) {
121 $instance_to_return = $this;
126 if ( $instance_to_return === $this ) {
128 $registered_plugins = array_merge( $this->_registered_plugins, array_values( $passed_instance->get_registered_plugins() ) );
130 $registered_plugins = array_merge( array_values( $this->_registered_plugins ), $instance_to_return->get_registered_plugins() );
133 $instance_to_return->set_registered_plugins( $registered_plugins );
135 return $instance_to_return;
142 if ( class_exists(
'GravityKitFoundation' ) ) {
146 $gk_foundation = apply_filters(
'gk/foundation/get-instance', null );
148 if ( ! $gk_foundation ) {
152 $gk_foundation->init();
167 public static function register( $plugin_file ) {
168 if ( is_null( self::$_instance ) ) {
169 self::$_instance =
new self( $plugin_file );
170 } elseif ( ! in_array( $plugin_file, self::$_instance->_registered_plugins ) ) {
171 self::$_instance->_registered_plugins[] = $plugin_file;
183 return self::$_instance;
207 $this->_registered_plugins = array_unique( $plugins );
218 if ( did_action(
'gk/foundation/initialized' ) ) {
222 add_action(
'wp_ajax_' . self::WP_AJAX_ACTION, [ $this,
'process_ajax_request' ] );
224 $this->_components = [
225 'settings' => SettingsFramework::get_instance(),
226 'licenses' => LicensesFramework::get_instance(),
227 'translations' => TranslationsFramework::get_instance(),
228 'logger' => LoggerFramework::get_instance(),
236 foreach ( $this->_components as $component => $instance ) {
237 if ( CoreHelpers::is_callable_class_method( [ $this->_components[ $component ],
'init' ] ) ) {
238 $this->_components[ $component ]->init();
242 self::$_request_unique_string = $this->encryption()->get_random_nonce();
245 $this->plugin_activation_handler()->fire_activation_hook();
249 add_action(
'admin_enqueue_scripts', [ $this,
'inline_scripts_and_styles' ], 20 );
251 add_action(
'admin_footer', [ $this,
'display_foundation_information' ] );
254 class_alias( __CLASS__,
'GravityKitFoundation' );
265 do_action(
'gk/foundation/initialized', $this );
277 'gk/foundation/settings/data/plugins',
278 function ( $plugins ) {
279 $gk_settings = $this->settings()->get_plugin_settings( self::ID );
284 if ( ! is_main_site() && empty( $gk_settings ) ) {
285 $gk_settings = $this->settings()->get_plugin_settings( self::ID, get_main_site_id() );
288 $default_settings = [
289 'support_email' => get_bloginfo(
'admin_email' ),
291 'no_conflict_mode' => 1,
296 $general_settings = [];
299 if ( defined(
'GV_PLUGIN_VERSION' ) && version_compare(
GV_PLUGIN_VERSION,
'2.16',
'<' ) ) {
300 $notice_1 = esc_html__(
'You are using a version of GravityView that does not yet support the new GravityKit settings framework.',
'gk-gravityview' );
303 esc_html_x(
'As such, the settings below will not apply to GravityView pages and you will have to continue using the [link]old settings[/link] until an updated version of the plugin is available. We apologize for the inconvenience as we work to update our products in a timely fashion.',
'Placeholders inside [] are not to be translated.',
'gk-gravityview' ),
305 '[link]' =>
'<a href="' . admin_url(
'edit.php?post_type=gravityview&page=gravityview_settings' ) .
'" class="text-blue-gv underline hover:text-gray-900 focus:text-gray-900 focus:no-underline focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900">',
311 <div
class=
"bg-yellow-50 p-4 rounded-md">
313 <div
class=
"flex-shrink-0">
314 <svg
class=
"h-5 w-5 text-yellow-400" xmlns=
"http://www.w3.org/2000/svg" viewBox=
"0 0 20 20" fill=
"currentColor" aria-hidden=
"true">
315 <path fill-rule=
"evenodd" d=
"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule=
"evenodd" />
331 $general_settings[] = [
332 'id' =>
'legacy_settings_notice',
337 $general_settings = array_merge(
341 'id' =>
'powered_by',
342 'type' =>
'checkbox',
343 'value' =>
Arr::get( $gk_settings,
'powered_by', $default_settings[
'powered_by'] ),
344 'title' => esc_html__(
'Display "Powered By" Link',
'gk-gravityview' ),
345 'description' => esc_html__(
'A "Powered by GravityKit" link will be displayed below some GravityKit products. Help us spread the word!',
'gk-gravityview' ),
348 'id' =>
'affiliate_id',
350 'value' =>
Arr::get( $gk_settings,
'affiliate_id' ),
351 'title' => esc_html__(
'Affiliate ID',
'gk-gravityview' ),
352 'description' => strtr(
353 esc_html_x(
'Earn money when people clicking your links become GravityKit customers. [link]Register as an affiliate[/link]!',
'Placeholders inside [] are not to be translated.',
'gk-gravityview' ),
355 '[link]' =>
'<a href="https://www.gravitykit.com/account/affiliates/?utm_source=in-plugin&utm_medium=setting&utm_content=Register%20as%20an%20affiliate" class="underline" rel="external">',
360 'id' =>
'powered_by',
367 'type' =>
'checkbox',
368 'value' =>
Arr::get( $gk_settings,
'beta', $default_settings[
'beta'] ),
369 'title' => esc_html__(
'Become a Beta Tester',
'gk-gravityview' ),
370 'description' => esc_html__(
'You will have early access to the latest GravityKit products. There may be bugs! If you encounter an issue, report it to help make GravityKit products better!',
'gk-gravityview' ),
375 $support_settings = [
377 'id' =>
'support_email',
380 'value' =>
Arr::get( $gk_settings,
'support_email', $default_settings[
'support_email'] ),
381 'title' => esc_html__(
'Support Email',
'gk-gravityview' ),
382 'description' => esc_html__(
'In order to provide responses to your support requests, please provide your email address.',
'gk-gravityview' ),
385 'rule' =>
'required',
386 'message' => esc_html__(
'Support email is required',
'gk-gravityview' ),
390 'message' => esc_html__(
'Please provide a valid email address',
'gk-gravityview' ),
395 'id' =>
'support_port',
396 'type' =>
'checkbox',
397 'value' =>
Arr::get( $gk_settings,
'support_port', $default_settings[
'support_port'] ),
398 'title' => esc_html__(
'Show Support Port',
'gk-gravityview' ),
399 'description' => ( esc_html__(
'The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.',
'gk-gravityview' ) .
401 esc_html_x(
'[image]Support Port icon[/image]',
'Placeholders inside [] are not to be translated.',
'gk-gravityview' ),
403 '[image]' =>
'<div style="margin-top: 1em; width: 7em;">![',
404 '[/image]' =>
'](' . CoreHelpers::get_assets_url(
'support-port-icon.jpg' ) .
')</div>',
411 $technical_settings = [
413 'id' =>
'no_conflict_mode',
414 'type' =>
'checkbox',
415 'value' =>
Arr::get( $gk_settings,
'no_conflict_mode', $default_settings[
'no_conflict_mode'] ),
416 'title' => esc_html__(
'Enable No-Conflict Mode',
'gk-gravityview' ),
417 'description' => esc_html__(
'No-conflict mode prevents extraneous scripts and styles from being printed on GravityKit admin pages, reducing conflicts with other plugins and themes.',
'gk-gravityview' ),
424 'title' =>
'GravityKit',
425 'defaults' => $default_settings,
426 'icon' => CoreHelpers::get_assets_url(
'gravitykit-icon.png' ),
429 'title' => esc_html__(
'General',
'gk-gravityview' ),
430 'settings' => $general_settings,
433 'title' => esc_html__(
'Support',
'gk-gravityview' ),
434 'settings' => $support_settings,
437 'title' => esc_html__(
'Technical',
'gk-gravityview' ),
438 'settings' => $technical_settings,
453 $all_settings = apply_filters(
'gk/foundation/settings', $all_settings );
455 return array_merge( $plugins, $all_settings );
471 '_wpNonce' => wp_create_nonce( self::ID ),
472 '_wpAjaxUrl' => admin_url(
'admin-ajax.php' ),
473 '_wpAjaxAction' => self::WP_AJAX_ACTION,
474 'ajaxRouter' => $router ?: self::AJAX_ROUTER,
488 $request = wp_parse_args(
493 'ajaxRouter' => null,
498 list ( $nonce, $payload, $router, $route ) = array_values( $request );
500 if ( ! is_array( $payload ) ) {
501 $payload = json_decode( stripslashes_deep( $payload ),
true );
504 $is_valid_nonce = wp_verify_nonce( $nonce, self::ID );
506 if ( ! wp_doing_ajax() || ! $is_valid_nonce ) {
507 wp_die(
false,
false, [
'response' => 403 ] );
519 $ajax_route_to_class_method_map = apply_filters(
"gk/foundation/ajax/{$router}/routes", [] );
521 $route_callback =
Arr::get( $ajax_route_to_class_method_map, $route );
523 if ( ! CoreHelpers::is_callable_function( $route_callback ) && ! CoreHelpers::is_callable_class_method( $route_callback ) ) {
524 wp_die(
false,
false, [
'response' => 404 ] );
539 $payload = apply_filters(
'gk/foundation/ajax/payload', $payload, $router, $route );
541 $result = call_user_func( $route_callback, $payload );
543 $result =
new Exception( $e->getMessage() );
558 $result = apply_filters(
'gk/foundation/ajax/result', $result, $router, $route, $payload );
560 return CoreHelpers::process_return( $result );
580 $inline_scripts = apply_filters(
'gk/foundation/inline-scripts', [] );
582 if ( ! empty( $inline_scripts ) ) {
586 foreach ( $inline_scripts as $script_data ) {
587 if ( isset( $script_data[
'dependencies'] ) ) {
588 $dependencies = array_merge( $dependencies, $script_data[
'dependencies'] );
591 if ( isset( $script_data[
'script'] ) ) {
592 $scripts[] = $script_data[
'script'];
596 wp_register_script( self::ID,
false, $dependencies );
597 wp_enqueue_script( self::ID );
598 wp_add_inline_script( self::ID, implode(
' ', $scripts ) );
610 $inline_styles = apply_filters(
'gk/foundation/inline-styles', [] );
612 if ( ! empty( $inline_styles ) ) {
616 foreach ( $inline_styles as $style_data ) {
617 if ( isset( $style_data[
'dependencies'] ) ) {
618 $dependencies = array_merge( $dependencies, $style_data[
'dependencies'] );
621 if ( isset( $style_data[
'style'] ) ) {
622 $styles[] = $style_data[
'style'];
626 wp_register_style( self::ID,
false );
627 wp_enqueue_style( self::ID );
628 wp_add_inline_style( self::ID, implode(
' ', $styles ) );
643 if (
'plugin_activation_handler' ===
$name ) {
647 if (
'helpers' ===
$name ) {
649 'core' =>
new CoreHelpers(),
650 'array' =>
new Arr(),
654 if ( ! isset( $this->_components[
$name ] ) ) {
660 $logger_name = isset( $arguments[0] ) ? $arguments[0] : null;
661 $logger_title = isset( $arguments[1] ) ? $arguments[1] : null;
663 return call_user_func_array( [ $this->_components[ $name ],
'get_instance' ], [ $logger_name, $logger_title ] );
665 return $this->_components[
$name ];
680 $instance = apply_filters(
'gk/foundation/get-instance', null );
682 return call_user_func_array( [ $instance,
$name ], $arguments );
694 return self::$_request_unique_string;
714 $display_foundation_information = apply_filters(
'gk/foundation/display_foundation_information',
true );
716 if ( ! $display_foundation_information ) {
720 $foundation_version = self::VERSION;
721 $foundation_source =
Arr::get( CoreHelpers::get_plugin_data( $this->_registered_plugins[
'foundation_source'] ),
'Name',
'<unknown plugin>' );
723 echo
"<!-- GravityKit Foundation v{$foundation_version} (loaded by {$foundation_source}) -->";
const GV_PLUGIN_VERSION(! GravityKit\GravityView\Foundation\meets_min_php_version_requirement(__FILE__, '7.2.0'))
Constants.
static get_instance()
Returns class instance.
__call( $name, array $arguments=[])
Magic method to get private class instances.
static get( $array, $key, $default=null)
{}
static get_instance( $secret_key='')
Returns class instance.
$_plugin_activation_handler
static get_instance()
Returns class instance.
set_registered_plugins( $plugins)
Sets a list of plugins that have instantiated Foundation.
configure_settings()
Configures general GravityKit settings.
__construct( $plugin_file)
Class constructor.
We use Laravel's Arr class for all array helper methods.
static get_ajax_params( $router)
Registers the GravityKit admin menu.
inline_scripts_and_styles()
Inlines scripts/styles.
static __callStatic( $name, array $arguments=[])
Magic method to get private class instances as static methods.
display_foundation_information()
Outputs an HTML comment with the Foundation version and the plugin that loaded it.
process_ajax_request()
Processes AJAX request and routes it to the appropriate endpoint.
static get_instance()
Returns class instance.
static $_request_unique_string
static get_request_unique_string()
Returns a unique value that was generated for this request.
Logging framework for GravityKit.
This class is responsible for handling plugin activation and deactivation hooks.
get_registered_plugins()
Returns a list of plugins that have instantiated Foundation.
init()
Initializes Foundation.