Skip to content

Commit

Permalink
Merge pull request #1322 from vektor-inc/develop
Browse files Browse the repository at this point in the history
[ Change version ] 1.39.2.0
  • Loading branch information
kurudrive authored Jul 11, 2022
2 parents 678d799 + fb70067 commit c2e97c8
Show file tree
Hide file tree
Showing 12 changed files with 1,281 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"tgmpa/tgm-plugin-activation": "dev-develop",
"yahnis-elsts/plugin-update-checker": "*",
"vektor-inc/vk-color-palette-manager": "^0.3.0",
"vektor-inc/vk-breadcrumb": "^0.2.3",
"vektor-inc/vk-breadcrumb": "^0.2.4",
"vektor-inc/vk-term-color": "^0.4.0"
},
"require-dev": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions inc/vk-blocks-pro/class-vk-blocks-pro-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* VK Blocks Pro Options class.
*
* @package vk-blocks
*/

/**
* VK_Blocks_Pro_Options
*/
class VK_Blocks_Pro_Options {

/**
* VK Blocks Pro Options schema
*
* @var array
*/
private $vk_blocks_pro_option_schema = array(
'display_vk_block_template' => array(
'type' => 'string',
'default' => 'display',
),
'new_faq_accordion' => array(
'type' => 'string',
'default' => 'disable',
),
);

/**
* VK Blocks License Option schema
*
* @var array
*/
private $license_key_option_scheme = array(
'vk_blocks_pro_license_key' => array(
'type' => 'string',
'default' => null,
),
);

/**
* Constructor.
*/
private function __construct() {
add_filter( 'vk_blocks_default_options_scheme', array( $this, 'vk_blocks_pro_default_options_scheme' ) );
}

/**
* Initialize
*
* @return VK_Blocks_Pro_Options
*/
public static function init() {
// static 宣言しているので既に定義されている場合は $instance に null は入らずに既存のインスタンスのまま.
static $instance = null;
return $instance ? $instance : $instance = new static();
}

/**
* Pro Option
*/
public function vk_blocks_pro_default_options_scheme() {
$array = $this->vk_blocks_pro_option_schema;
if ( vk_blocks_is_license_setting() ) {
$array = array_merge( $this->license_key_option_scheme, $this->vk_blocks_pro_option_schema );
}
return $array;
}
}
3 changes: 3 additions & 0 deletions inc/vk-blocks-pro/vk-blocks-pro-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// Pro 用の管理画面を読み込み.
require_once dirname( __FILE__ ) . '/admin-pro/admin-pro.php';

require_once dirname( __FILE__ ) . '/class-vk-blocks-pro-options.php';
VK_Blocks_Pro_Options::init();

/**
* VK Blocks Pro Get Options
*
Expand Down
241 changes: 241 additions & 0 deletions inc/vk-blocks/class-vk-blocks-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?php
/**
* VK Blocks Options class.
*
* @package vk-blocks
*/

/**
* VK_Blocks_Options
*/
class VK_Blocks_Options {

/**
* Initialize
*
* @return VK_Blocks_Options
*/
public static function init() {
// static 宣言しているので既に定義されている場合は $instance に null は入らずに既存のインスタンスのまま.
static $instance = null;
return $instance ? $instance : $instance = new static();
}

/**
* Constructor.
*/
private function __construct() {
add_action( 'init', array( $this, 'register_setting' ) );
}

/**
* Options scheme
*
* @return number
*/
public static function options_scheme() {
$default_options_schema = array(
'balloon_border_width' => array(
'type' => 'number',
'default' => 1,
),
'margin_unit' => array(
'type' => 'string',
'default' => 'rem',
),
'margin_size' => array(
'type' => 'object',
'items' => array(
'lg' => array(
'type' => 'object',
'items' => array(
'mobile' => array(
'type' => 'number',
'default' => null,
),
'tablet' => array(
'type' => 'number',
'default' => null,
),
'pc' => array(
'type' => 'number',
'default' => null,
),
),
),
'md' => array(
'type' => 'object',
'items' => array(
'mobile' => array(
'type' => 'number',
'default' => null,
),
'tablet' => array(
'type' => 'number',
'default' => null,
),
'pc' => array(
'type' => 'number',
'default' => null,
),
),
),
'sm' => array(
'type' => 'object',
'items' => array(
'mobile' => array(
'type' => 'number',
'default' => null,
),
'tablet' => array(
'type' => 'number',
'default' => null,
),
'pc' => array(
'type' => 'number',
'default' => null,
),
),
),
),
),
'load_separate_option' => array(
'type' => 'boolean',
'default' => false,
),
);
$array = array_merge( $default_options_schema, apply_filters( 'vk_blocks_default_options_scheme', array() ) );
return $array;
}

/**
* 吹き出し数
*
* @return number
*/
public static function balloon_image_number() {
return apply_filters( 'vk_blocks_image_number', 15 );
}

/**
* 吹き出しschema 生成
*
* @return $balloon_meta_schema
*/
public function balloon_meta_schema() {
$number = self::balloon_image_number();
$return_array = array();
$return_array['default_icons'] = array(
'type' => 'object',
);
for ( $i = 1; $i <= $number; $i++ ) {
$return_array['default_icons']['items'][ $i ] = array(
'type' => 'object',
'items' => array(
'name' => array(
'type' => 'string',
'default' => null,
),
'src' => array(
'type' => 'string',
'default' => null,
),
),
);
};
return $return_array;
}

/**
* Get Defaults
*
* @param array $schema option defaults.
*
* @return options
*/
public static function get_defaults( $schema ) {
$default = array();
foreach ( $schema as $key => $value ) {
$default[ $key ] = 'object' === $value['type'] ? self::get_defaults( $value['items'] ) : $value['default'];
}
return $default;
}

/**
* Get properties
*
* @param array $schema option schema.
*
* @return options
*/
public static function get_properties( $schema ) {
$properties = array();
foreach ( $schema as $key => $value ) {
$properties[ $key ] = array(
'type' => $value['type'],
);

if ( 'object' === $value['type'] ) {
$properties[ $key ]['properties'] = self::get_properties( $value['items'] );
}
}
return $properties;
}

/**
* Get Balloon Meta Options
*
* @return options
*/
public static function get_balloon_meta_options() {
$options = get_option( 'vk_blocks_balloon_meta' );
$number = self::balloon_image_number();
$defaults = array();
$defaults['default_icons'] = array();
for ( $i = 1; $i <= $number; $i++ ) {
$defaults['default_icons'][ $i ] = array(
'name' => null,
'src' => null,
);
};
$options = wp_parse_args( $options, $defaults );
return $options;
}

/**
* Register Setting
*
* @see https://developer.wordpress.org/reference/functions/register_setting/#comment-5289
*/
public function register_setting() {
register_setting(
'vk_blocks_setting',
'vk_blocks_options',
array(
'type' => 'object',
'show_in_rest' => array(
'schema' => array(
'type' => 'object',
'properties' => self::get_properties( self::options_scheme() ),
),
),
'default' => self::get_defaults( self::options_scheme() ),
)
);

register_setting(
'vk_blocks_setting',
'vk_blocks_balloon_meta',
array(
'type' => 'object',
'show_in_rest' => array(
'schema' => array(
'type' => 'object',
'properties' => self::get_properties( self::balloon_meta_schema() ),
),
),
'default' => self::get_defaults( $this->balloon_meta_schema() ),
)
);
}
}
2 changes: 2 additions & 0 deletions inc/vk-blocks/vk-blocks-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
require_once dirname( __FILE__ ) . '/style/balloon.php';
require_once dirname( __FILE__ ) . '/style/hidden-extension.php';
require_once dirname( __FILE__ ) . '/class-vk-blocks-print-css-variables.php';
require_once dirname( __FILE__ ) . '/class-vk-blocks-options.php';
VK_Blocks_Options::init();

/**
* スペーサーのサイズの配列
Expand Down
Loading

0 comments on commit c2e97c8

Please sign in to comment.