blocks
1 year ago
dynamic-tags
3 months ago
pattern-library
1 year ago
utils
2 years ago
class-do-css.php
2 years ago
class-dynamic-content.php
6 months ago
class-dynamic-tag-security.php
6 months ago
class-enqueue-css.php
1 year ago
class-legacy-attributes.php
4 years ago
class-map-deprecated-attributes.php
2 years ago
class-meta-handler.php
3 months ago
class-plugin-update.php
1 year ago
class-query-loop.php
2 years ago
class-query-utils.php
3 months ago
class-render-blocks.php
1 year ago
class-rest.php
1 year ago
class-settings.php
1 year ago
dashboard.php
1 year ago
defaults.php
1 year ago
deprecated.php
1 year ago
functions.php
6 months ago
general.php
8 months ago
class-settings.php
153 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Our settings page. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Build our settings page. |
| 14 | */ |
| 15 | class GenerateBlocks_Settings { |
| 16 | /** |
| 17 | * Instance. |
| 18 | * |
| 19 | * @access private |
| 20 | * @var object Instance |
| 21 | */ |
| 22 | private static $instance; |
| 23 | |
| 24 | /** |
| 25 | * Initiator. |
| 26 | * |
| 27 | * @return object initialized object of class. |
| 28 | */ |
| 29 | public static function get_instance() { |
| 30 | if ( ! isset( self::$instance ) ) { |
| 31 | self::$instance = new self(); |
| 32 | } |
| 33 | |
| 34 | return self::$instance; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Constructor. |
| 39 | */ |
| 40 | public function __construct() { |
| 41 | add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
| 42 | add_action( 'generateblocks_settings_area', array( $this, 'add_settings_container' ) ); |
| 43 | add_action( 'generateblocks_settings_area', array( $this, 'add_blocks_version_settings_container' ), 100 ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Add our Dashboard menu item. |
| 48 | */ |
| 49 | public function add_menu() { |
| 50 | $settings = add_submenu_page( |
| 51 | 'generateblocks', |
| 52 | __( 'Settings', 'generateblocks' ), |
| 53 | __( 'Settings', 'generateblocks' ), |
| 54 | 'manage_options', |
| 55 | 'generateblocks-settings', |
| 56 | array( $this, 'settings_page' ), |
| 57 | 1 |
| 58 | ); |
| 59 | |
| 60 | remove_submenu_page( 'generateblocks', 'generateblocks' ); |
| 61 | |
| 62 | add_action( "admin_print_scripts-$settings", array( $this, 'enqueue_scripts' ) ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Enqueue our scripts. |
| 67 | */ |
| 68 | public function enqueue_scripts() { |
| 69 | $generateblocks_deps = array( 'wp-api', 'wp-i18n', 'wp-components', 'wp-element', 'wp-api-fetch' ); |
| 70 | |
| 71 | $assets_file = GENERATEBLOCKS_DIR . 'dist/settings.asset.php'; |
| 72 | $compiled_assets = file_exists( $assets_file ) |
| 73 | ? require $assets_file |
| 74 | : false; |
| 75 | |
| 76 | $assets = |
| 77 | isset( $compiled_assets['dependencies'] ) && |
| 78 | isset( $compiled_assets['version'] ) |
| 79 | ? $compiled_assets |
| 80 | : [ |
| 81 | 'dependencies' => $generateblocks_deps, |
| 82 | 'version' => filemtime( GENERATEBLOCKS_DIR . 'dist/settings.js' ), |
| 83 | ]; |
| 84 | |
| 85 | wp_enqueue_script( |
| 86 | 'generateblocks-settings', |
| 87 | GENERATEBLOCKS_DIR_URL . 'dist/settings.js', |
| 88 | $assets['dependencies'], |
| 89 | $assets['version'], |
| 90 | true |
| 91 | ); |
| 92 | |
| 93 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| 94 | wp_set_script_translations( 'generateblocks-settings', 'generateblocks' ); |
| 95 | } |
| 96 | |
| 97 | wp_localize_script( |
| 98 | 'generateblocks-settings', |
| 99 | 'generateBlocksSettings', |
| 100 | array( |
| 101 | 'settings' => wp_parse_args( |
| 102 | get_option( 'generateblocks', array() ), |
| 103 | generateblocks_get_option_defaults() |
| 104 | ), |
| 105 | 'gpContainerWidth' => function_exists( 'generate_get_option' ) ? generate_get_option( 'container_width' ) : false, |
| 106 | 'gpContainerWidthLink' => function_exists( 'generate_get_option' ) ? |
| 107 | add_query_arg( |
| 108 | rawurlencode( 'autofocus[control]' ), |
| 109 | rawurlencode( 'generate_settings[container_width]' ), |
| 110 | wp_customize_url() |
| 111 | ) : |
| 112 | false, |
| 113 | 'useV1Blocks' => generateblocks_use_v1_blocks(), |
| 114 | ) |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Add settings container. |
| 120 | * |
| 121 | * @since 1.2.0 |
| 122 | */ |
| 123 | public function add_settings_container() { |
| 124 | echo '<div id="gblocks-block-default-settings"></div>'; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Add blocks version settings container. |
| 129 | * |
| 130 | * @since 2.0.0 |
| 131 | */ |
| 132 | public function add_blocks_version_settings_container() { |
| 133 | echo '<div id="gblocks-blocks-version-settings"></div>'; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Output our Dashboard HTML. |
| 138 | * |
| 139 | * @since 0.1 |
| 140 | */ |
| 141 | public function settings_page() { |
| 142 | ?> |
| 143 | <div class="wrap gblocks-dashboard-wrap"> |
| 144 | <div class="generateblocks-settings-area"> |
| 145 | <?php do_action( 'generateblocks_settings_area' ); ?> |
| 146 | </div> |
| 147 | </div> |
| 148 | <?php |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | GenerateBlocks_Settings::get_instance(); |
| 153 |