'100px',
'overlap_inline_value' => 'min(10vw, 100px)',
'overlap_gradient_value' => '100px',
'shadow_blur' => '1em',
'shadow_opacity' => '.15',
);
/**
* Cache for saved options.
*
* @since 1.1.0
* @access public
* @var array
*/
public static $options = array();
/**
* Initialization.
*
* @since 1.1.0
*
* @return void
*/
public static function init() {
// Processing
// Actions
add_action( 'admin_menu', __CLASS__ . '::admin_menu' );
add_action( 'admin_init', __CLASS__ . '::register_settings' );
// Filters
add_filter( 'plugin_action_links_' . plugin_basename( ABS_FILE ), __CLASS__ . '::plugin_action_links' );
} // /init
/**
* Add option page to admin menu.
*
* @since 1.1.0
*
* @return void
*/
public static function admin_menu() {
// Processing
add_options_page(
esc_html__( 'Abs - Additional Block Styles plugin settings', 'additional-block-styles' ),
esc_html__( 'Abs', 'additional-block-styles' ),
self::$capability,
self::$admin_page_slug,
__CLASS__ . '::admin_page'
);
} // /admin_menu
/**
* Render admin page.
*
* @since 1.1.0
*
* @return void
*/
public static function admin_page() {
// Output
require_once ABS_PATH . 'includes/parts/admin-page.php';
} // /admin_page
/**
* Register setting options.
*
* @since 1.1.0
* @version 1.4.0
*
* @return void
*/
public static function register_settings() {
// Processing
// Register single option in database for the plugin.
register_setting(
self::$settings_group,
self::$option_name,
array(
'type' => 'array',
'description' => esc_html__( 'Abs - Additional Block Styles plugin settings', 'additional-block-styles' ),
'default' => self::$option_defaults,
'sanitize_callback' => function( $value ) {
return array_map( 'sanitize_text_field', (array) $value );
}
)
);
// Options for overlapping.
$section = 'overlap';
add_settings_section(
$section,
esc_html__( 'Overlapping', 'additional-block-styles' ),
'',
self::$admin_page_slug
);
$key = 'overlap_value';
add_settings_field(
$key,
esc_html__( 'Overlap value', 'additional-block-styles' ),
__CLASS__ . '::form_field',
self::$admin_page_slug,
$section,
array(
'name' => $key,
'id' => $key,
'label_for' => $key,
'description' =>
esc_html__( 'Set a positive value here.', 'additional-block-styles' )
. ' '
. sprintf(
/* translators: %s: CSS style rule name with link to more details page at developer.mozilla.org. */
__( 'You can use any value valid for %s CSS style.', 'additional-block-styles' ),
'margin-top'
)
. '
'
. sprintf(
/* translators: %s: default plugin option value. */
__( 'Default value: %s', 'additional-block-styles' ),
'' . self::$option_defaults[ $key ] . ''
),
)
);
$key = 'overlap_inline_value';
add_settings_field(
$key,
esc_html__( 'Pull left/right value', 'additional-block-styles' ),
__CLASS__ . '::form_field',
self::$admin_page_slug,
$section,
array(
'name' => $key,
'id' => $key,
'label_for' => $key,
'description' =>
esc_html__( 'Set a positive value here.', 'additional-block-styles' )
. ' '
. sprintf(
/* translators: %s: CSS style rule name with link to more details page at developer.mozilla.org. */
__( 'You can use any value valid for %s CSS style.', 'additional-block-styles' ),
'margin-left'
)
. '
'
. sprintf(
/* translators: %s: default plugin option value. */
__( 'Default value: %s', 'additional-block-styles' ),
'' . self::$option_defaults[ $key ] . ''
),
)
);
$key = 'overlap_gradient_value';
add_settings_field(
$key,
esc_html__( 'Gradient overlap value', 'additional-block-styles' ),
__CLASS__ . '::form_field',
self::$admin_page_slug,
$section,
array(
'name' => $key,
'id' => $key,
'label_for' => $key,
'description' =>
esc_html__( 'This sets the size of overlap gradient for "Gradient" style of Media & Text block.', 'additional-block-styles' )
. ' '
. esc_html__( 'Set a positive value here.', 'additional-block-styles' )
. ' '
. sprintf(
/* translators: %s: CSS style rule name with link to more details page at developer.mozilla.org. */
__( 'You can use any value valid for %s CSS style.', 'additional-block-styles' ),
'margin-left'
)
. '
'
. sprintf(
/* translators: %s: default plugin option value. */
__( 'Default value: %s', 'additional-block-styles' ),
'' . self::$option_defaults[ $key ] . ''
),
)
);
// Options for shadows.
$section = 'shadow';
add_settings_section(
$section,
esc_html__( 'Shadows', 'additional-block-styles' ),
'',
self::$admin_page_slug
);
$key = 'shadow_blur';
add_settings_field(
$key,
esc_html__( 'Shadow blur radius', 'additional-block-styles' ),
__CLASS__ . '::form_field',
self::$admin_page_slug,
$section,
array(
'name' => $key,
'id' => $key,
'label_for' => $key,
'description' =>
sprintf(
/* translators: %s: CSS style rule name with link to more details page at developer.mozilla.org. */
__( 'You can use any value valid for %s CSS style.', 'additional-block-styles' ),
'box-shadow <blur-radius>'
)
. '
'
. sprintf(
/* translators: %s: default plugin option value. */
__( 'Default value: %s', 'additional-block-styles' ),
'' . self::$option_defaults[ $key ] . ''
),
)
);
$key = 'shadow_opacity';
add_settings_field(
$key,
esc_html__( 'Shadow opacity', 'additional-block-styles' ),
__CLASS__ . '::form_field',
self::$admin_page_slug,
$section,
array(
'name' => $key,
'id' => $key,
'label_for' => $key,
'description' =>
sprintf(
/* translators: %s: CSS style rule name with link to more details page at developer.mozilla.org. */
__( 'You can use any value valid for %s CSS style.', 'additional-block-styles' ),
'opacity'
)
. '
'
. sprintf(
/* translators: %s: default plugin option value. */
__( 'Default value: %s', 'additional-block-styles' ),
'' . self::$option_defaults[ $key ] . ''
),
)
);
} // /register_settings
/**
* Render setting field.
*
* @since 1.1.0
*
* @param array $args
*
* @return void
*/
public static function form_field( array $args = array() ) {
// Variables
$args = wp_parse_args( $args, array(
'name' => null,
'id' => null,
'type' => null,
'description' => null,
) );
// Output
if ( file_exists( ABS_PATH . 'includes/parts/field-name--' . $args['name'] . '.php' ) ) {
include ABS_PATH . 'includes/parts/field-name--' . $args['name'] . '.php';
} elseif ( file_exists( ABS_PATH . 'includes/parts/field-type--' . $args['type'] . '.php' ) ) {
include ABS_PATH . 'includes/parts/field-type--' . $args['type'] . '.php';
} else {
echo '
' . '' . '
'; if ( $args['description'] ) { echo '' . wp_kses( $args['description'], array( 'br' => array(), 'code' => array(), 'em' => array(), 'mark' => array(), 'strong' => array(), 'a' => array( 'href' => array(), 'rel' => array(), 'title' => array(), 'target' => array(), ), ) ) . '
'; } } } // /form_field /** * Get plugin option value. * * @since 1.1.0 * * @param string $option * * @return mixed */ public static function get( string $option ) { // Processing if ( empty( self::$options ) ) { self::$options = (array) get_option( self::$option_name, self::$option_defaults ); } // Output if ( isset( self::$options[ $option ] ) && '' !== trim( self::$options[ $option ] ) ) { return self::$options[ $option ]; } elseif ( isset( self::$option_defaults[ $option ] ) ) { return self::$option_defaults[ $option ]; } else { return null; } } // /get /** * Set plugin action links. * * @since 1.1.0 * * @param array $links * * @return array */ public static function plugin_action_links( array $links ) { // Processing $links[] = '' . esc_html_x( 'Settings', 'Plugin action link.', 'additional-block-styles' ) . ''; // Output return $links; } // /plugin_action_links }