Update API
This commit is contained in:
@@ -33,14 +33,35 @@ class Opalestate_Admin {
|
||||
* enqueue editor.js for edit mode
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
$screen = get_current_screen();
|
||||
$screen_id = $screen ? $screen->id : '';
|
||||
|
||||
wp_enqueue_style( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/admin.css', [], '3.0.3' );
|
||||
|
||||
$suffix = '';
|
||||
wp_enqueue_style( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/css/select2.min.css', null, '1.3' );
|
||||
wp_enqueue_script( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/js/select2.min.js', null, '1.3', true );
|
||||
|
||||
wp_enqueue_script( 'opalestate-country-select', OPALESTATE_PLUGIN_URL . 'assets/js/country-select.js', [ 'jquery' ], null, true );
|
||||
wp_enqueue_script( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', [ 'jquery' ], null, true );
|
||||
wp_enqueue_script( 'opalestate-country-select', OPALESTATE_PLUGIN_URL . 'assets/js/country-select.js', [ 'jquery' ], OPALESTATE_VERSION, true );
|
||||
wp_enqueue_script( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', [ 'jquery' ], OPALESTATE_VERSION, true );
|
||||
wp_register_script( 'jquery-blockui', OPALESTATE_PLUGIN_URL . 'assets/3rd/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
|
||||
wp_register_script( 'opal-clipboard', OPALESTATE_PLUGIN_URL . 'assets/3rd/opal-clipboard.js', array( 'jquery' ), OPALESTATE_VERSION, true );
|
||||
|
||||
// API settings.
|
||||
if ( 'opalestate_property_page_opalestate-settings' === $screen_id && isset( $_GET['tab'] ) && 'api_keys' == $_GET['tab'] ) {
|
||||
wp_register_script( 'opalestate-api-keys', OPALESTATE_PLUGIN_URL . 'assets/js/api-keys' . $suffix . '.js', array( 'jquery', 'opalestate-admin', 'underscore', 'backbone', 'wp-util', 'jquery-blockui', 'opal-clipboard' ),
|
||||
OPALESTATE_VERSION, true );
|
||||
wp_enqueue_script( 'opalestate-api-keys' );
|
||||
wp_localize_script(
|
||||
'opalestate-api-keys',
|
||||
'opalestate_admin_api_keys',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
|
||||
'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'opalestate-pro' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,11 +88,8 @@ class Opalestate_Admin {
|
||||
'settings/property.php',
|
||||
] );
|
||||
|
||||
//
|
||||
|
||||
// Get it started
|
||||
$Opalestate_Settings = new Opalestate_Plugin_Settings();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -338,56 +338,6 @@ if ( ! function_exists( 'opalestate_license_key_callback' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display the API Keys
|
||||
*
|
||||
* @return void
|
||||
* @since 2.0
|
||||
*/
|
||||
function opalestate_api_keys_callback() {
|
||||
if ( ! current_user_can( 'manage_opalestate_settings' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
do_action( 'opalestate_tools_api_keys_keys_before' );
|
||||
|
||||
require_once OPALESTATE_PLUGIN_DIR . 'inc/admin/class-api-keys-table.php';
|
||||
|
||||
$keys_table_list = new Opalestate_API_Keys_Table();
|
||||
$keys_table_list->prepare_items();
|
||||
|
||||
echo '<input type="hidden" name="page" value="wc-settings" />';
|
||||
echo '<input type="hidden" name="tab" value="api" />';
|
||||
echo '<input type="hidden" name="section" value="keys" />';
|
||||
|
||||
$keys_table_list->views();
|
||||
$keys_table_list->search_box( esc_html__( 'Search Key', 'opalestate-pro' ), 'key' );
|
||||
$keys_table_list->display();
|
||||
?>
|
||||
|
||||
|
||||
<p>
|
||||
<?php printf(
|
||||
__( 'API keys allow users to use the <a href="%s">Opalestate REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%s">Zapi_keyser</a>.',
|
||||
'opalestate-pro' ),
|
||||
'https://wpopal.com/opalestate/documentation/opalestate-api_keys-reference/',
|
||||
'https://wpopal.com/addons/opalestate/'
|
||||
); ?>
|
||||
</p>
|
||||
|
||||
<style>
|
||||
.opalestate_properties_page_opalestate-settings .opalestate-submit-wrap {
|
||||
display: none; /* Hide Save settings button on System Info Tab (not needed) */
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
|
||||
do_action( 'opalestate_tools_api_keys_keys_after' );
|
||||
}
|
||||
|
||||
add_action( 'opalestate_settings_tab_api_keys_keys', 'opalestate_api_keys_callback' );
|
||||
|
||||
/**
|
||||
* Hook Callback
|
||||
*
|
||||
@@ -596,4 +546,4 @@ function opalestate_ajax_search_username() {
|
||||
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_opalestate_ajax_search_username', 'opalestate_ajax_search_username' );
|
||||
add_action( 'wp_ajax_opalestate_ajax_search_username', 'opalestate_ajax_search_username' );
|
||||
|
||||
@@ -46,9 +46,10 @@ class Opalestate_Plugin_Settings {
|
||||
*/
|
||||
protected $options_page = '';
|
||||
|
||||
protected $subtabs = array();
|
||||
protected $subtabs = [];
|
||||
|
||||
protected $setting_object = [];
|
||||
|
||||
protected $setting_object = array();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -67,23 +68,32 @@ class Opalestate_Plugin_Settings {
|
||||
// add_action( 'cmb2_render_license_key', 'opalestate_license_key_callback', 10, 5 );
|
||||
add_action( "cmb2_save_options-page_fields", [ $this, 'settings_notices' ], 10, 3 );
|
||||
|
||||
|
||||
add_action( 'cmb2_render_api_keys', 'opalestate_api_keys_callback', 10, 5 );
|
||||
|
||||
// Include CMB CSS in the head to avoid FOUC
|
||||
add_action( "admin_print_styles-opalestate_properties_page_opalestate-settings", [ 'CMB2_hookup', 'enqueue_cmb_css' ] );
|
||||
}
|
||||
|
||||
public function admin_menu() {
|
||||
//Settings
|
||||
$opalestate_settings_page = add_submenu_page( 'edit.php?post_type=opalestate_property', esc_html__( 'Settings', 'opalestate-pro' ), esc_html__( 'Settings', 'opalestate-pro' ), 'manage_opalestate_settings',
|
||||
// Settings
|
||||
$opalestate_settings_page = add_submenu_page(
|
||||
'edit.php?post_type=opalestate_property',
|
||||
esc_html__( 'Opalestate Settings', 'opalestate-pro' ),
|
||||
esc_html__( 'Settings', 'opalestate-pro' ),
|
||||
'manage_opalestate_settings',
|
||||
'opalestate-settings',
|
||||
[ $this, 'admin_page_display' ] );
|
||||
|
||||
// addons setting
|
||||
$opalestate_settings_page = add_submenu_page( 'edit.php?post_type=opalestate_property', esc_html__( 'Addons', 'opalestate-pro' ), esc_html__( 'Addons', 'opalestate-pro' ), 'manage_options', 'opalestate-addons',
|
||||
do_action( 'load-' . $opalestate_settings_page, $this );
|
||||
|
||||
// Addons
|
||||
$opalestate_addons_page = add_submenu_page(
|
||||
'edit.php?post_type=opalestate_property',
|
||||
esc_html__( 'Opalestate Addons', 'opalestate-pro' ),
|
||||
esc_html__( 'Addons', 'opalestate-pro' ),
|
||||
'manage_options',
|
||||
'opalestate-addons',
|
||||
[ $this, 'admin_addons_page_display' ] );
|
||||
|
||||
do_action( 'load-' . $opalestate_addons_page, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +103,6 @@ class Opalestate_Plugin_Settings {
|
||||
*/
|
||||
public function init() {
|
||||
register_setting( $this->key, $this->key );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +128,7 @@ class Opalestate_Plugin_Settings {
|
||||
$tabs['licenses'] = esc_html__( 'Licenses', 'opalestate-pro' );
|
||||
}
|
||||
|
||||
$tabs['api_keys'] = esc_html__( 'API', 'opalestate-pro' );
|
||||
$tabs['api_keys'] = esc_html__( 'API', 'opalestate-pro' );
|
||||
$tabs['3rd_party'] = esc_html__( '3rd Party', 'opalestate-pro' );
|
||||
|
||||
return apply_filters( 'opalestate_settings_tabs', $tabs );
|
||||
@@ -129,15 +138,16 @@ class Opalestate_Plugin_Settings {
|
||||
require_once opalestate_get_admin_view( 'addons/list.php' );
|
||||
}
|
||||
|
||||
public function get_subtabs_link ( $tab_id , $stab_id ) {
|
||||
public function get_subtabs_link( $tab_id, $stab_id ) {
|
||||
$tab_url = esc_url( add_query_arg( [
|
||||
'settings-updated' => false,
|
||||
'tab' => $tab_id,
|
||||
'subtab' => $stab_id
|
||||
'subtab' => $stab_id,
|
||||
] ) );
|
||||
|
||||
return $tab_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin page markup. Mostly handled by CMB2
|
||||
*
|
||||
@@ -147,31 +157,30 @@ class Opalestate_Plugin_Settings {
|
||||
|
||||
$active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->opalestate_get_settings_tabs() ) ? $_GET['tab'] : 'general';
|
||||
|
||||
$sub_active_tab = isset( $_GET['subtab'] ) ? sanitize_text_field( $_GET['subtab'] ): '';
|
||||
$sub_active_tab = isset( $_GET['subtab'] ) ? sanitize_text_field( $_GET['subtab'] ) : '';
|
||||
|
||||
$tabs_fields = $this->opalestate_settings( $active_tab );
|
||||
$sub_tabs_fields = array();
|
||||
$tabs_fields = $this->opalestate_settings( $active_tab );
|
||||
$sub_tabs_fields = [];
|
||||
|
||||
if( empty($sub_active_tab) && $this->subtabs ){
|
||||
$first = array_flip( $this->subtabs );
|
||||
$sub_active_tab = reset( $first );
|
||||
if ( empty( $sub_active_tab ) && $this->subtabs ) {
|
||||
$first = array_flip( $this->subtabs );
|
||||
$sub_active_tab = reset( $first );
|
||||
}
|
||||
|
||||
if( $this->subtabs ){
|
||||
if ( $this->subtabs ) {
|
||||
$sub_tabs_fields = $this->setting_object->get_subtabs_content( $sub_active_tab );
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
<div class="wrap opalestate_settings_page cmb2_options_page <?php echo $this->key; ?>">
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<?php
|
||||
foreach ( $this->opalestate_get_settings_tabs() as $tab_id => $tab_name ) {
|
||||
|
||||
$tab_url = esc_url( add_query_arg( [
|
||||
'settings-updated' => false,
|
||||
'tab' => $tab_id,
|
||||
'subtab' => false
|
||||
] ) );
|
||||
'subtab' => false,
|
||||
], admin_url( 'edit.php?post_type=opalestate_property&page=opalestate-settings' ) ) );
|
||||
|
||||
$active = $active_tab == $tab_id ? ' nav-tab-active' : '';
|
||||
|
||||
@@ -183,31 +192,31 @@ class Opalestate_Plugin_Settings {
|
||||
?>
|
||||
</h2>
|
||||
<div class="form-settings-wrap">
|
||||
<?php if( $this->subtabs ): ?>
|
||||
<div class="subtab-settings-navs">
|
||||
<ul>
|
||||
|
||||
<?php foreach( $this->subtabs as $key => $value ): ?>
|
||||
<li>
|
||||
<a <?php if( $key == $sub_active_tab ): ?>class="active"<?php endif; ?> href="<?php echo esc_url( $this->get_subtabs_link( $active_tab, $key ) ); ?>">
|
||||
<?php echo $value; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php if ( $this->subtabs ): ?>
|
||||
<div class="subtab-settings-navs">
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif ; ?>
|
||||
<?php foreach ( $this->subtabs as $key => $value ): ?>
|
||||
<li>
|
||||
<a <?php if ( $key == $sub_active_tab ): ?>class="active"<?php endif; ?> href="<?php echo esc_url( $this->get_subtabs_link( $active_tab, $key ) ); ?>">
|
||||
<?php echo $value; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="form-settings-form">
|
||||
<?php if( $sub_active_tab ): ?>
|
||||
<?php cmb2_metabox_form( $sub_tabs_fields , $this->key ); ?>
|
||||
<?php else : ?>
|
||||
<?php cmb2_metabox_form( $tabs_fields , $this->key ); ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-settings-form">
|
||||
<?php if ( $sub_active_tab ): ?>
|
||||
<?php cmb2_metabox_form( $sub_tabs_fields, $this->key ); ?>
|
||||
<?php else : ?>
|
||||
<?php cmb2_metabox_form( $tabs_fields, $this->key ); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div><!-- .wrap -->
|
||||
|
||||
@@ -230,29 +239,31 @@ class Opalestate_Plugin_Settings {
|
||||
'numberposts' => -1,
|
||||
] );
|
||||
|
||||
$general = array();
|
||||
$opalestate_settings = array();
|
||||
|
||||
$general = [];
|
||||
$opalestate_settings = [];
|
||||
|
||||
//Return all settings array if necessary
|
||||
|
||||
if ( $active_tab === null ) {
|
||||
return apply_filters( 'opalestate_registered_settings', $opalestate_settings );
|
||||
}
|
||||
|
||||
$output = apply_filters( 'opalestate_registered_' . $active_tab . '_settings', isset( $opalestate_settings[ $active_tab ] ) ? $opalestate_settings[ $active_tab ] : [] );
|
||||
|
||||
if( empty($output) ){
|
||||
$class = "Opalestate_Settings_".ucfirst( $active_tab )."_Tab";
|
||||
$output = apply_filters( 'opalestate_registered_' . $active_tab . '_settings', isset( $opalestate_settings[ $active_tab ] ) ? $opalestate_settings[ $active_tab ] : [] );
|
||||
|
||||
if( class_exists($class) ){
|
||||
$tab = new $class( $this->key );
|
||||
$this->setting_object = $tab;
|
||||
$this->subtabs = $tab->get_subtabs();
|
||||
if ( empty( $output ) ) {
|
||||
$class = "Opalestate_Settings_" . ucfirst( $active_tab ) . "_Tab";
|
||||
|
||||
return $tab->get_tab_content( $this->key );
|
||||
if ( class_exists( $class ) ) {
|
||||
$tab = new $class( $this->key );
|
||||
$this->setting_object = $tab;
|
||||
$this->subtabs = $tab->get_subtabs();
|
||||
|
||||
return $tab->get_tab_content( $this->key );
|
||||
}
|
||||
return array( $active_tab => array() );
|
||||
|
||||
return [ $active_tab => [] ];
|
||||
}
|
||||
|
||||
// Add other tabs and settings fields as needed
|
||||
return $output;
|
||||
|
||||
@@ -303,4 +314,4 @@ class Opalestate_Plugin_Settings {
|
||||
|
||||
throw new Exception( 'Invalid property: ' . $field );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user