-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1322 from vektor-inc/develop
[ Change version ] 1.39.2.0
- Loading branch information
Showing
12 changed files
with
1,281 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ), | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.