first commit
This commit is contained in:
204
vendor/wpcfto/settings/settings.php
vendored
Normal file
204
vendor/wpcfto/settings/settings.php
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
class WPCFTO_Settings
|
||||
{
|
||||
|
||||
public $option_name;
|
||||
public $page_args;
|
||||
public $fields;
|
||||
private $setup;
|
||||
|
||||
function __construct($option_name, $page_args, $fields, $setup)
|
||||
{
|
||||
|
||||
$this->option_name = $option_name;
|
||||
$this->page_args = $page_args;
|
||||
$this->fields = $fields;
|
||||
$this->setup = $setup;
|
||||
|
||||
add_action('admin_menu', array($this, 'settings_page'), 1000);
|
||||
add_action('wp_ajax_wpcfto_save_settings', array($this, 'stm_save_settings'));
|
||||
|
||||
if (!empty($this->setup['admin_bar_title'])) {
|
||||
add_action('admin_bar_menu', array($this, 'admin_bar_button'), 40);
|
||||
add_action('wp_head', array($this, 'admin_bar_styles'));
|
||||
add_action('admin_head', array($this, 'admin_bar_styles'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function admin_bar_styles() {
|
||||
$selector = "#wp-admin-bar-{$this->setup['option_name']}";
|
||||
?>
|
||||
<style>
|
||||
<?php echo esc_attr($selector) ?> img {
|
||||
max-width: 25px;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
}
|
||||
</style>
|
||||
<?php }
|
||||
|
||||
function admin_bar_button($wp_admin_bar)
|
||||
{
|
||||
|
||||
|
||||
$url = add_query_arg('page', $this->setup['page']['menu_slug'], admin_url());
|
||||
$wpcfto_logo = (!empty($this->setup['logo'])) ? $this->setup['logo'] : STM_WPCFTO_URL . '/metaboxes/assets/images/stm-logo.svg';
|
||||
$title = $this->setup['admin_bar_title'];
|
||||
$menu = "<img src='{$wpcfto_logo}' /> {$title}";
|
||||
|
||||
$args = array(
|
||||
'id' => $this->setup['option_name'],
|
||||
'title' => $menu,
|
||||
'href' => $url,
|
||||
'meta' => array(
|
||||
'title' => $title
|
||||
)
|
||||
);
|
||||
$wp_admin_bar->add_node($args);
|
||||
}
|
||||
|
||||
function settings_page()
|
||||
{
|
||||
|
||||
if (current_user_can('manage_options')) {
|
||||
|
||||
if (!empty($this->page_args['parent_slug'])) {
|
||||
$r = add_submenu_page(
|
||||
$this->page_args['parent_slug'],
|
||||
$this->page_args['page_title'],
|
||||
$this->page_args['menu_title'],
|
||||
'manage_options',
|
||||
$this->page_args['menu_slug'],
|
||||
array($this, 'settings_page_view')
|
||||
);
|
||||
} else {
|
||||
add_menu_page(
|
||||
$this->page_args['page_title'],
|
||||
$this->page_args['menu_title'],
|
||||
'manage_options',
|
||||
$this->page_args['menu_slug'],
|
||||
array($this, 'settings_page_view'),
|
||||
$this->page_args['icon'],
|
||||
$this->page_args['position']
|
||||
);
|
||||
}
|
||||
|
||||
do_action("wpcfto_screen_{$this->option_name}_added");
|
||||
}
|
||||
}
|
||||
|
||||
public static function stm_get_post_type_array($post_type, $args = array())
|
||||
{
|
||||
$r = array(
|
||||
'' => __('Choose Page', 'wp-custom-fields-theme-options'),
|
||||
);
|
||||
|
||||
$default_args = array(
|
||||
'post_type' => $post_type,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish'
|
||||
);
|
||||
|
||||
$q = get_posts(wp_parse_args($args, $default_args));
|
||||
|
||||
if (!empty($q)) {
|
||||
foreach ($q as $post_data) {
|
||||
$r[$post_data->ID] = $post_data->post_title;
|
||||
}
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
function wpcfto_settings()
|
||||
{
|
||||
|
||||
$args = array();
|
||||
$args[$this->option_name] = $this->fields;
|
||||
|
||||
return apply_filters($this->option_name, array(
|
||||
'id' => $this->option_name,
|
||||
'args' => $args
|
||||
));
|
||||
}
|
||||
|
||||
function wpcfto_get_settings()
|
||||
{
|
||||
return get_option($this->option_name, array());
|
||||
}
|
||||
|
||||
function settings_page_view()
|
||||
{
|
||||
$metabox = $this->wpcfto_settings();
|
||||
$settings = $this->wpcfto_get_settings();
|
||||
$page = $this->page_args;
|
||||
$wpcfto_title = (!empty($this->setup['title'])) ? $this->setup['title'] : '';
|
||||
$wpcfto_sub_title = (!empty($this->setup['sub_title'])) ? $this->setup['sub_title'] : '';
|
||||
$wpcfto_logo = (!empty($this->setup['logo'])) ? $this->setup['logo'] : STM_WPCFTO_URL . '/metaboxes/assets/images/stm-logo.svg';
|
||||
|
||||
foreach ($metabox['args'][$this->option_name] as $section_name => $section) {
|
||||
foreach ($section['fields'] as $field_name => $field) {
|
||||
$default_value = (!empty($field['value'])) ? $field['value'] : '';
|
||||
$metabox['args'][$this->option_name][$section_name]['fields'][$field_name]['value'] = (isset($settings[$field_name])) ? $settings[$field_name] : $default_value;
|
||||
}
|
||||
}
|
||||
include STM_WPCFTO_PATH . '/settings/view/main.php';
|
||||
}
|
||||
|
||||
public static function get_my_settings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function stm_save_settings()
|
||||
{
|
||||
|
||||
check_ajax_referer('wpcfto_save_settings', 'nonce');
|
||||
|
||||
if (!current_user_can('manage_options')) {
|
||||
die;
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['name'])) {
|
||||
die;
|
||||
}
|
||||
$id = sanitize_text_field($_REQUEST['name']);
|
||||
$settings = array();
|
||||
$request_body = file_get_contents('php://input');
|
||||
if (!empty($request_body)) {
|
||||
$request_body = json_decode($request_body, true);
|
||||
foreach ($request_body as $section_name => $section) {
|
||||
foreach ($section['fields'] as $field_name => $field) {
|
||||
$settings[$field_name] = $field['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action('wpcfto_settings_saved', $id, $settings);
|
||||
|
||||
$updateOption = update_option($id, $settings);
|
||||
|
||||
do_action('wpcfto_after_settings_saved', $id, $settings);
|
||||
|
||||
wp_send_json($updateOption);
|
||||
}
|
||||
}
|
||||
|
||||
add_action('init', function () {
|
||||
$theme_options_page = apply_filters('wpcfto_options_page_setup', array());
|
||||
|
||||
if (!empty($theme_options_page)) {
|
||||
foreach ($theme_options_page as $setup) {
|
||||
if (empty($setup['option_name']) or empty($setup['page']) or !isset($setup['fields'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new WPCFTO_Settings($setup['option_name'], $setup['page'], $setup['fields'], $setup);
|
||||
}
|
||||
}
|
||||
});
|
||||
53
vendor/wpcfto/settings/view/header.php
vendored
Normal file
53
vendor/wpcfto/settings/view/header.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $id
|
||||
* @var $wpcfto_title
|
||||
* @var $wpcfto_sub_title
|
||||
* @var $wpcfto_logo
|
||||
*/
|
||||
|
||||
$only_logo = empty($wpcfto_title) && empty($wpcfto_sub_title);
|
||||
?>
|
||||
|
||||
|
||||
<div v-cloak v-if="data !== ''" class="wpcfto_settings_head">
|
||||
|
||||
<div class="wpcfto_settings_head__side">
|
||||
|
||||
<div class="wpcfto_settings_head__logo <?php if($only_logo) echo esc_attr('wpcfto_settings_head__logo_only') ?>">
|
||||
<img src="<?php echo esc_url($wpcfto_logo); ?>" alt="Logo">
|
||||
</div>
|
||||
|
||||
<div class="wpcfto_settings_head__label">
|
||||
<?php if(!empty($wpcfto_title)): ?>
|
||||
<div class="wpcfto_settings_head__title">
|
||||
<?php echo esc_attr($wpcfto_title); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($wpcfto_sub_title)): ?>
|
||||
<div class="wpcfto_settings_head__subtitle">
|
||||
<?php echo esc_attr($wpcfto_sub_title); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="wpcfto_settings_head__content">
|
||||
|
||||
<div class="wpcfto_search_group">
|
||||
<input type="text" name="" value="" class="wpcfto-search-field" placeholder="<?php esc_html_e( 'Search', 'wp-custom-fields-theme-options' ); ?>" />
|
||||
</div>
|
||||
|
||||
<a href="#"
|
||||
@click.prevent="saveSettings('<?php echo esc_attr( $id ); ?>')"
|
||||
v-bind:class="{'loading': loading}"
|
||||
class="button load_button" id="publish">
|
||||
<span><?php esc_html_e( 'Save Settings', 'wp-custom-fields-theme-options' ); ?></span>
|
||||
<i class="lnr lnr-sync"></i>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
42
vendor/wpcfto/settings/view/main.php
vendored
Normal file
42
vendor/wpcfto/settings/view/main.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var $metabox
|
||||
* @var $page
|
||||
* @var $wpcfto_title
|
||||
* @var $wpcfto_sub_title
|
||||
* @var $wpcfto_logo
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} //Exit if accessed directly
|
||||
|
||||
if(empty($wpcfto_title)) $wpcfto_title = $page['page_title'];
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
$id = $metabox['id'];
|
||||
$sections = $metabox['args'][ $id ];
|
||||
$source_id = 'data-source="settings"';
|
||||
|
||||
|
||||
do_action( "wpcfto_settings_screen_{$id}_before" );
|
||||
|
||||
if ( ! empty( $sections ) ) : ?>
|
||||
|
||||
<div class="wpcfto-settings"
|
||||
v-bind:class="'data-' + data.length"
|
||||
data-vue="<?php echo sanitize_text_field( $id ); ?>" <?php echo stm_wpcfto_filtered_output( $source_id ); ?>>
|
||||
|
||||
<?php include STM_WPCFTO_PATH . '/settings/view/header.php'; ?>
|
||||
|
||||
<?php require_once( STM_WPCFTO_PATH . '/metaboxes/metabox-display.php' ); ?>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php endif;
|
||||
|
||||
do_action( "wpcfto_settings_screen_{$id}_after" );
|
||||
Reference in New Issue
Block a user