Skip to content

Commit db934e5

Browse files
Improve advanced settings
1 parent fb15f71 commit db934e5

File tree

2 files changed

+106
-28
lines changed

2 files changed

+106
-28
lines changed

admin/index.php

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ function rich_snippet_dashboard() {
9494
<li><a href="#tab-4" class="nav-tab">' . esc_html__( 'Customization', 'rich-snippets' ) . '</a></li>
9595
9696
<li><a href="#tab-3" class="nav-tab">' . esc_html__( 'FAQs', 'rich-snippets' ) . '</a></li>
97-
<li><a href="#tab-5" class="nav-tab">' . esc_html__( 'Getting Started', 'rich-snippets' ) . '</a></li>
98-
</ul>
97+
<li><a href="#tab-5" class="nav-tab">' . esc_html__( 'Getting Started', 'rich-snippets' ) . '</a></li>
98+
<li><a href="#tab-6" class="nav-tab">' . esc_html__( 'Advanced Settings', 'rich-snippets' ) . '</a></li>
99+
</ul>
99100
<div class="clear"></div>
100101
<div class="panel-container bsf-panel">
101102
<div id="tab-1">
@@ -843,11 +844,38 @@ function rich_snippet_dashboard() {
843844
</div>
844845
</div>
845846
</div>
846-
</div>
847+
</div>
848+
849+
<div id="tab-6">
850+
<div id="poststuff">
851+
<div id="postbox-container-18" class="postbox-container">
852+
<div class="postbox">
853+
<h3 class="hndle"><span>' . esc_html__( 'Advanced Settings', 'rich-snippets' ) . '</span></h3>
854+
<div class="inside">
855+
<form id="aiosrs_advanced_form" method="post">
856+
<input type="hidden" name="aiosrs_advanced_nonce_field" value="' . esc_attr( wp_create_nonce( 'aiosrs_advanced_form_action' ) ) . '" />
857+
<table class="bsf_metabox">
858+
<tr>
859+
<td>
860+
<label for="aiosrs_analytics_optin">' . esc_html__( 'Enable feature', 'rich-snippets' ) . '</label>
861+
<div class="bsf-tooltip"><span class="dashicons dashicons-info"></span><span class="bsf-tooltiptext">' . esc_html__( 'Share anonymous usage data to help improve the plugin.', 'rich-snippets' ) . '</span></div>
862+
<input style="margin-left:10px;" type="checkbox" name="aiosrs_analytics_optin" id="aiosrs_analytics_optin" value="yes" ' . checked( 'yes', get_option( 'aiosrs_analytics_optin', 'no' ), false ) . ' />
863+
</td>
864+
</tr>
865+
<tr>
866+
<td><input type="submit" class="button-primary" name="aiosrs_advanced_submit" value="' . esc_html__( 'Save', 'rich-snippets' ) . '" /></td>
867+
</tr>
868+
</table>
869+
</form>
870+
</div>
871+
</div>
872+
</div>
873+
</div>
874+
</div>
847875
848-
</div>
849-
</div>
850-
<div class="postbox-container" id="bsf-postbox-container-1" >
876+
</div>
877+
</div>
878+
<div class="postbox-container" id="bsf-postbox-container-1" >
851879
<div id="side-sortables" class="meta-box-sortables ui-sortable">
852880
<div class="postbox bsf-woocommerce-setting closed">
853881
<button type="button" class="handlediv" aria-expanded="false"><span class="screen-reader-text">' . esc_html__( 'Toggle panel: Frontend Options', 'rich-snippets' ) . '</span><span class="toggle-indicator" aria-hidden="true"></span></button>
@@ -871,13 +899,13 @@ function rich_snippet_dashboard() {
871899
</table>
872900
</form>
873901
</div>
874-
</div>';
902+
</div>';
875903

876-
$allowed_html = array(
877-
'div' => array(
878-
'class' => array(),
879-
'id' => array(),
880-
),
904+
$allowed_html = array(
905+
'div' => array(
906+
'class' => array(),
907+
'id' => array(),
908+
),
881909
'button' => array(
882910
'type' => array(),
883911
'class' => array(),
@@ -945,11 +973,12 @@ function rich_snippet_dashboard() {
945973
jQuery("#postbox-container-7").css("width","35%");
946974
jQuery("#postbox-container-8").css("width","35%");
947975
jQuery("#postbox-container-9").css("width","35%");
948-
jQuery("#postbox-container-10").css("width","35%");
949-
jQuery("#postbox-container-11").css({"width":"87%","padding-right":"2%"});
950-
jQuery(".postbox h3").click( function() {
951-
jQuery(jQuery(this).parent().get(0)).toggleClass("closed");
952-
});
976+
jQuery("#postbox-container-10").css("width","35%");
977+
jQuery("#postbox-container-11").css({"width":"87%","padding-right":"2%"});
978+
jQuery("#postbox-container-18").css({"width":"87%","padding-right":"2%"});
979+
jQuery(".postbox h3").click( function() {
980+
jQuery(jQuery(this).parent().get(0)).toggleClass("closed");
981+
});
953982
jQuery(".handlediv").click( function() {
954983
jQuery(jQuery(this).parent().get(0)).toggleClass("closed");
955984
});
@@ -1112,9 +1141,19 @@ function rich_snippet_dashboard() {
11121141
$args[ $option ] = sanitize_text_field( $_POST[ $option ] );
11131142
}
11141143
}
1115-
$status = update_option( 'bsf_service', $args );
1116-
display_status( $status );
1117-
}
1144+
$status = update_option( 'bsf_service', $args );
1145+
display_status( $status );
1146+
}
1147+
}
1148+
if ( isset( $_POST['aiosrs_advanced_submit'] ) ) {
1149+
if ( ! isset( $_POST['aiosrs_advanced_nonce_field'] ) || ! wp_verify_nonce( $_POST['aiosrs_advanced_nonce_field'], 'aiosrs_advanced_form_action' ) || ! current_user_can( 'manage_options' ) ) {
1150+
print 'Sorry, your nonce did not verify.';
1151+
exit;
1152+
} else {
1153+
$value = isset( $_POST['aiosrs_analytics_optin'] ) ? 'yes' : 'no';
1154+
$status = update_option( 'aiosrs_analytics_optin', $value );
1155+
display_status( $status );
1156+
}
11181157
}
11191158
/**
11201159
* Display status.

index.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public function __construct() {
4646
add_action( 'admin_menu', array( $this, 'register_custom_menu_page' ) );
4747
add_action( 'admin_init', array( $this, 'set_styles' ) );
4848

49-
add_action( 'admin_init', array( $this, 'bsf_color_scripts' ) );
49+
add_action( 'admin_init', array( $this, 'bsf_color_scripts' ) );
50+
51+
add_action( 'admin_init', array( $this, 'aiosrs_maybe_migrate_analytics_tracking' ) );
52+
53+
add_action( 'admin_init', array( $this, 'aiosrs_remove_general_usage_tracking_field' ), 15 );
5054

5155
add_filter( 'plugins_loaded', array( $this, 'rich_snippet_translation' ) );
5256
add_action( 'admin_enqueue_scripts', array( $this, 'post_enqueue' ) );
@@ -363,8 +367,8 @@ public function iris_enqueue_scripts() {
363367
/**
364368
* Bsf_color_scripts.
365369
*/
366-
public function bsf_color_scripts() {
367-
global $wp_version;
370+
public function bsf_color_scripts() {
371+
global $wp_version;
368372
$bsf_script_array = array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'media-upload', 'thickbox' );
369373

370374
// styles required for cmb.
@@ -382,9 +386,44 @@ public function bsf_color_scripts() {
382386
$bsf_script_array[] = 'farbtastic';
383387
$bsf_style_array[] = 'farbtastic';
384388

385-
}
386-
}
387-
}
389+
}
390+
}
391+
392+
/**
393+
* Migrate analytics tracking option from old bsf key to new one.
394+
*
395+
* @return void
396+
*/
397+
public function aiosrs_maybe_migrate_analytics_tracking() {
398+
$old_tracking = get_option( 'bsf_analytics_optin', false );
399+
$new_tracking = get_option( 'aiosrs_analytics_optin', false );
400+
if ( 'yes' === $old_tracking && false === $new_tracking ) {
401+
update_option( 'aiosrs_analytics_optin', 'yes' );
402+
$time = get_option( 'bsf_analytics_installed_time' );
403+
if ( $time ) {
404+
update_option( 'aiosrs_analytics_installed_time', $time );
405+
}
406+
}
407+
}
408+
409+
/**
410+
* Remove usage tracking checkbox from WordPress General settings.
411+
*
412+
* @since 1.7.2
413+
* @return void
414+
*/
415+
public function aiosrs_remove_general_usage_tracking_field() {
416+
global $wp_settings_fields;
417+
418+
$field_id = 'aiosrs-analytics-optin';
419+
420+
if ( isset( $wp_settings_fields['general']['default'][ $field_id ] ) ) {
421+
unset( $wp_settings_fields['general']['default'][ $field_id ] );
422+
}
423+
424+
unregister_setting( 'general', 'aiosrs_analytics_optin' );
425+
}
426+
}
388427
}
389428
require_once plugin_dir_path( __FILE__ ) . 'functions.php';
390429
if ( is_admin() ) {
@@ -405,8 +444,8 @@ public function bsf_color_scripts() {
405444
$bsf_analytics = BSF_Analytics_Loader::get_instance();
406445

407446
$bsf_analytics->set_entity(
408-
array(
409-
'bsf' => array(
447+
array(
448+
'aiosrs' => array(
410449
'product_name' => 'All In One Schema Rich Snippets',
411450
'path' => plugin_dir_path( __FILE__ ) . 'admin/bsf-analytics',
412451
'author' => 'Brainstorm Force',

0 commit comments

Comments
 (0)