first commit
This commit is contained in:
@@ -0,0 +1,575 @@
|
||||
<?php
|
||||
namespace Nimble;
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* REGISTER PAGE
|
||||
/* ------------------------------------------------------------------------- */
|
||||
// function nb_register_settings() {
|
||||
// add_option( 'myplugin_option_name', 'This is my option value.');
|
||||
// register_setting( 'myplugin_options_group', 'myplugin_option_name', '\Nimble\myplugin_callback' );
|
||||
// }
|
||||
// add_action( 'admin_init', '\Nimble\nb_register_settings' );
|
||||
|
||||
function nb_register_options_page() {
|
||||
if ( !sek_current_user_can_access_nb_ui() )
|
||||
return;
|
||||
add_options_page(
|
||||
apply_filters( 'nb_admin_settings_title', __('Nimble Builder', 'text-domain') ),
|
||||
apply_filters( 'nb_admin_settings_title', __('Nimble Builder', 'text-domain') ),
|
||||
'manage_options',
|
||||
NIMBLE_OPTIONS_PAGE,
|
||||
'\Nimble\nb_options_page'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', '\Nimble\nb_register_options_page');
|
||||
|
||||
// callback of add_options_page()
|
||||
// fired @'admin_menu'
|
||||
function nb_options_page() {
|
||||
$option_tabs = Nimble_Manager()->admin_option_tabs;
|
||||
$active_tab_id = nb_get_active_option_tab();
|
||||
$default_title = esc_html( get_admin_page_title() );
|
||||
$page_title = isset( $option_tabs[$active_tab_id] ) ? $option_tabs[$active_tab_id]['page_title'] : $default_title;
|
||||
$page_title = empty($page_title) ? $default_title : $page_title;
|
||||
?>
|
||||
|
||||
<div id="nimble-options" class="wrap">
|
||||
<h1 class="nb-option-page-title">
|
||||
<?php
|
||||
printf('<span class="sek-nimble-title-icon"><img src="%1$s" alt="Build with Nimble Builder"></span>',
|
||||
esc_url( NIMBLE_BASE_URL.'/assets/img/nimble/nimble_icon.svg?ver='.NIMBLE_VERSION )
|
||||
);
|
||||
echo apply_filters( 'nimble_parse_admin_text', esc_html( $page_title ) ) . wp_kses_post( apply_filters( 'nimble_option_title_icon_after', '' ) );
|
||||
?>
|
||||
</h1>
|
||||
<div class="nav-tab-wrapper">
|
||||
<?php
|
||||
$allowed_tags = array(
|
||||
'div' => array('class'=>true),
|
||||
'span' => array('class'=>true),
|
||||
'img' => array('class'=>true, 'src'=>true, 'alt'=>true),
|
||||
);
|
||||
foreach ($option_tabs as $tab_id => $tab_data ) {
|
||||
printf('<a class="nav-tab %1$s" href="%2$s">%3$s</a>',
|
||||
$tab_id === nb_get_active_option_tab() ? 'nav-tab-active' : '',
|
||||
esc_url( admin_url( NIMBLE_OPTIONS_PAGE_URL ) . '&tab=' . $tab_id ),
|
||||
wp_kses($tab_data['title'], $allowed_tags)
|
||||
);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="tab-content-wrapper">
|
||||
<?php
|
||||
$_cb = $option_tabs[$active_tab_id]['content'];
|
||||
if( is_string( $_cb ) && !empty( $_cb ) ) {
|
||||
if ( function_exists( $_cb ) ) {
|
||||
call_user_func( $_cb );
|
||||
} else {
|
||||
echo esc_attr($_cb);
|
||||
}
|
||||
} else if ( is_array($_cb) && 2 == count($_cb) ) {
|
||||
if ( is_object($_cb[0]) ) {
|
||||
$to_return = call_user_func( array( $_cb[0] , $_cb[1] ) );
|
||||
}
|
||||
//instantiated with an instance property holding the object ?
|
||||
else if ( class_exists($_cb[0]) ) {
|
||||
|
||||
/* PHP 5.3- compliant*/
|
||||
$class_vars = get_class_vars( $_cb[0] );
|
||||
|
||||
if ( isset( $class_vars[ 'instance' ] ) && method_exists( $class_vars[ 'instance' ], $_cb[1]) ) {
|
||||
$to_return = call_user_func( array( $class_vars[ 'instance' ] , $_cb[1] ) );
|
||||
}
|
||||
|
||||
else {
|
||||
$_class_obj = new $_cb[0]();
|
||||
if ( method_exists($_class_obj, $_cb[1]) )
|
||||
$to_return = call_user_func( array( $_class_obj, $_cb[1] ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
</div><!-- .wrap -->
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* ADD SETTINGS LINKS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
function nb_settings_link($links) {
|
||||
$doc_link = sprintf('<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a>', 'https://docs.presscustomizr.com/article/337-getting-started-with-the-nimble-builder-plugin', __('Docs', 'text-doma') );
|
||||
array_unshift($links, $doc_link );
|
||||
$settings_link = sprintf('<a href="%1$s">%2$s</a>',
|
||||
add_query_arg( array( 'tab' => 'options' ), admin_url( NIMBLE_OPTIONS_PAGE_URL ) ),
|
||||
__('Settings', 'text-doma')
|
||||
);
|
||||
array_unshift($links, $settings_link );
|
||||
return $links;
|
||||
}
|
||||
add_filter("plugin_action_links_".plugin_basename(NIMBLE_PLUGIN_FILE), '\Nimble\nb_settings_link' );
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* SAVE OPTION HOOK + CUSTOMIZABLE REDIRECTION
|
||||
/* ------------------------------------------------------------------------- */
|
||||
// fired @'admin_post'
|
||||
function nb_save_options() {
|
||||
do_action('nb_admin_post');
|
||||
//wp_safe_redirect( urldecode( admin_url( NIMBLE_OPTIONS_PAGE_URL ) ) );
|
||||
nb_admin_redirect();
|
||||
}
|
||||
add_action( 'admin_post', '\Nimble\nb_save_options' );
|
||||
|
||||
|
||||
// fired @'admin_post'
|
||||
function nb_admin_redirect() {
|
||||
$url = sanitize_text_field(
|
||||
wp_unslash( $_POST['_wp_http_referer'] ) // Input var okay.
|
||||
);
|
||||
// Default option url : urldecode( admin_url( NIMBLE_OPTIONS_PAGE_URL ) )
|
||||
$url = urldecode( $url );
|
||||
$url = empty($url) ? urldecode( admin_url( NIMBLE_OPTIONS_PAGE_URL ) ) : $url;
|
||||
// Finally, redirect back to the admin page.
|
||||
// Note : filter 'nimble_admin_redirect_url' is used in NB pro to add query params used to display warning/error messages
|
||||
wp_safe_redirect( apply_filters('nimble_admin_redirect_url', $url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// @return bool
|
||||
function nb_has_valid_nonce( $option_group = 'nb-options-save', $nonce = 'nb-options-nonce' ) {
|
||||
// If the field isn't even in the $_POST, then it's invalid.
|
||||
if ( !isset( $_POST[$nonce] ) ) { // Input var okay.
|
||||
return false;
|
||||
}
|
||||
return wp_verify_nonce( wp_unslash( $_POST[$nonce] ), $option_group );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* REGISTER TABS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
Nimble_Manager()->admin_option_tabs = array();
|
||||
// @return void
|
||||
function nb_register_option_tab( $tab ) {
|
||||
$tab = wp_parse_args( $tab, array(
|
||||
'id' => '',
|
||||
'title' => '',
|
||||
'page_title' => '',
|
||||
'content' => '',
|
||||
));
|
||||
Nimble_Manager()->admin_option_tabs[$tab['id']] = $tab;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function nb_get_active_option_tab() {
|
||||
// check that we have a tab param and that this tab is registered
|
||||
$tab_id = isset( $_GET['tab'] ) ? sanitize_text_field($_GET['tab']) : 'welcome';
|
||||
if ( !array_key_exists( $tab_id, Nimble_Manager()->admin_option_tabs ) ) {
|
||||
sek_error_log( __FUNCTION__ . ' error => invalid tab');
|
||||
$tab_id = 'welcome';
|
||||
}
|
||||
return $tab_id;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* WELCOME PAGE
|
||||
/* ------------------------------------------------------------------------- */
|
||||
nb_register_option_tab([
|
||||
'id' => 'welcome',
|
||||
'title' => __('Welcome', 'text-doma'),
|
||||
'page_title' => __('Nimble Builder', 'nimble' ),
|
||||
'content' => '\Nimble\print_welcome_page',
|
||||
]);
|
||||
function print_welcome_page() {
|
||||
?>
|
||||
<div class="nimble-welcome-content">
|
||||
<?php echo wp_kses_post(sek_get_welcome_block()); ?>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<hr/>
|
||||
<div>
|
||||
<h2><?php _e('Watch the video below for a brief overview of Nimble Builder features', 'text-doma'); ?></h2>
|
||||
<iframe src="https://player.vimeo.com/video/328473405?loop=1&title=0&byline=0&portrait=0" width="640" height="424" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* DATA CLEANING for #826
|
||||
/* ------------------------------------------------------------------------- */
|
||||
// Fired when click on button in admin options
|
||||
// introduced for https://github.com/presscustomizr/nimble-builder/issues/826
|
||||
function sek_clean_all_nimble_data() {
|
||||
if ( !isset( $_GET['clean_nb'] ) )
|
||||
return;
|
||||
|
||||
// Do we have a nonce passed ?
|
||||
if ( !isset( $_GET['ecnon'] ) )
|
||||
return;
|
||||
|
||||
// validate the nonce and verify the user as permission to save.
|
||||
if ( !wp_verify_nonce( wp_unslash( $_GET['ecnon'] ), 'nb-base-options' ) || !current_user_can( 'manage_options' ) )
|
||||
return;
|
||||
|
||||
// Nimble CPT for skoped sections, for user templates, for user sections
|
||||
$nb_cpt_list = [ 'NIMBLE_CPT', 'NIMBLE_TEMPLATE_CPT', 'NIMBLE_SECTION_CPT' ];
|
||||
foreach( $nb_cpt_list as $nb_cpt ) {
|
||||
if ( !defined( $nb_cpt ) )
|
||||
continue;
|
||||
$nb_cpt = constant($nb_cpt);
|
||||
$query = new \WP_Query(
|
||||
array(
|
||||
'post_type' => $nb_cpt,
|
||||
'post_status' => get_post_stati(),
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true,
|
||||
'cache_results' => true,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'lazy_load_term_meta' => false,
|
||||
)
|
||||
);
|
||||
if ( !is_array( $query->posts ) || empty( $query->posts ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $query->posts as $post_object ) {
|
||||
//permanently delete post ( unlike wp_trash_post() )
|
||||
wp_delete_post($post_object->ID);
|
||||
}
|
||||
}
|
||||
|
||||
// Nimble options
|
||||
$nb_opts = [
|
||||
'NIMBLE_OPT_SEKTION_POST_INDEX',
|
||||
'NIMBLE_OPT_NAME_FOR_GLOBAL_OPTIONS',
|
||||
'NIMBLE_OPT_FOR_MODULE_CSS_READING_STATUS',
|
||||
'NIMBLE_OPT_NAME_FOR_MOST_USED_FONTS',
|
||||
'NIMBLE_OPT_FOR_GLOBAL_CSS',
|
||||
'NIMBLE_OPT_NAME_FOR_SECTION_JSON',
|
||||
'NIMBLE_OPT_NAME_FOR_BACKWARD_FIXES',
|
||||
// admin options
|
||||
'NIMBLE_OPT_NAME_FOR_SHORTCODE_PARSING',
|
||||
'NIMBLE_OPT_NAME_FOR_DEBUG_MODE'
|
||||
];
|
||||
foreach( $nb_opts as $opt_name ) {
|
||||
if ( !defined( $opt_name ) )
|
||||
continue;
|
||||
$opt_name = constant($opt_name);
|
||||
delete_option( $opt_name );
|
||||
}
|
||||
|
||||
// clean other options like : nimble_start_date, nimble_started_with_version, nimble_version,
|
||||
foreach( [
|
||||
'nimble_start_date',
|
||||
'nimble_started_with_version',
|
||||
'nimble_version_upgraded_from',
|
||||
'nimble_version',
|
||||
'nimble_last_update_notice',
|
||||
'__nimble_options__'//<= deprecated option name
|
||||
] as $opt_name ) {
|
||||
delete_option( $opt_name );
|
||||
}
|
||||
|
||||
// clean options like nimble___skp__post_page_1010 ( old way to map skope_id and skoped post )
|
||||
sek_clean_options_starting_like( 'nimble___');
|
||||
sek_clean_options_starting_like( 'nimblebuilder_pro_');
|
||||
|
||||
// Nimble transients
|
||||
$nb_transients = [
|
||||
'NIMBLE_FEEDBACK_NOTICE_ID',
|
||||
'NIMBLE_FAWESOME_TRANSIENT_ID',
|
||||
'NIMBLE_GFONTS_TRANSIENT_ID',
|
||||
'NIMBLE_FEEDBACK_STATUS_TRANSIENT_ID',
|
||||
'NIMBLE_API_CHECK_TRANSIENT_ID'
|
||||
];
|
||||
foreach( $nb_transients as $trans_id ) {
|
||||
if ( !defined( $trans_id ) )
|
||||
continue;
|
||||
$trans_id = constant($trans_id);
|
||||
delete_transient( $trans_id );
|
||||
}
|
||||
// => remove all other transients
|
||||
sek_clean_transients_like( 'nimble_' );//'nimble_api_posts', 'nimble_api_tmpl_' . $tmpl_name
|
||||
sek_clean_transients_like( 'nimble_preset_sections_' );//old transient for storing preset sections. Now fetched remotely. See #802
|
||||
sek_clean_transients_like( 'section_params_transient' );//old transient that may still be there
|
||||
sek_clean_transients_like( 'section_params_transient' );//old transient that may still be there
|
||||
|
||||
|
||||
// Nimble CSS stylesheets
|
||||
$css_dir_list = [ 'NIMBLE_DEPREC_ONE_CSS_FOLDER_NAME', 'NIMBLE_DEPREC_TWO_CSS_FOLDER_NAME', 'NIMBLE_CSS_FOLDER_NAME' ];
|
||||
global $wp_filesystem;
|
||||
require_once ( ABSPATH . '/wp-admin/includes/file.php' );
|
||||
WP_Filesystem();
|
||||
$upload_dir = wp_get_upload_dir();
|
||||
|
||||
foreach( $css_dir_list as $css_dir ) {
|
||||
if ( !defined( $css_dir ) )
|
||||
continue;
|
||||
$css_dir = constant( $css_dir );
|
||||
if ( is_multisite() ) {
|
||||
$site = get_site();
|
||||
$network_id = $site->site_id;
|
||||
$site_id = $site->blog_id;
|
||||
$css_dir = trailingslashit( $css_dir ) . trailingslashit( $network_id ) . $site_id;
|
||||
}
|
||||
|
||||
$folder_path = wp_normalize_path( trailingslashit( $upload_dir['basedir'] ) . $css_dir );
|
||||
if ( $wp_filesystem->exists( $folder_path ) ) {
|
||||
$wp_filesystem->rmdir( $folder_path, true );
|
||||
}
|
||||
}
|
||||
return 'success';
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* OPTIONS PAGE
|
||||
/* ------------------------------------------------------------------------- */
|
||||
nb_register_option_tab([
|
||||
'id' => 'options',
|
||||
'title' => __('Options', 'text-doma'),
|
||||
'page_title' => __('Nimble Builder Options', 'nimble' ),
|
||||
'content' => '\Nimble\print_options_page',
|
||||
]);
|
||||
function print_options_page() {
|
||||
?>
|
||||
<form method="post" action="<?php echo esc_html( admin_url( 'admin-post.php' ) ); ?>">
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Shortcodes', 'text_doma'); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php _e('Shortcodes', 'text_doma'); ?></span></legend>
|
||||
<?php
|
||||
$shortcode_opt_val = get_option( NIMBLE_OPT_NAME_FOR_SHORTCODE_PARSING );
|
||||
?>
|
||||
<label for="nb_shortcodes_parsed_in_czr"><input name="nb_shortcodes_parsed_in_czr" type="checkbox" id="nb_shortcodes_parsed_in_czr" value="on" <?php checked( $shortcode_opt_val, 'on' ); ?>>
|
||||
<?php _e('Parse shortcodes when building your pages in the customizer', 'text_doma'); ?></label>
|
||||
<p class="description"><?php _e('Shortcodes are disabled by default when customizing to prevent any conflicts with Nimble Builder interface.', 'text_doma'); ?></p>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Widgets Module', 'text_doma'); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php _e('Widgets module', 'text_doma'); ?></span></legend>
|
||||
<?php
|
||||
$widget_disabled_opt_val = get_option( NIMBLE_OPT_NAME_FOR_DISABLING_WIDGET_MODULE );
|
||||
?>
|
||||
<label for="nb_widgets_disabled_in_czr"><input name="nb_widgets_disabled_in_czr" type="checkbox" id="nb_widgets_disabled_in_czr" value="on" <?php checked( $widget_disabled_opt_val, 'on' ); ?>>
|
||||
<?php _e('Disable the Widgets Module', 'text_doma'); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Debug Mode', 'text_doma'); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php _e('Debug Mode', 'text_doma'); ?></span></legend>
|
||||
<?php
|
||||
$nb_debug_mode_opt_val = get_option( NIMBLE_OPT_NAME_FOR_DEBUG_MODE );
|
||||
?>
|
||||
<label for="nb_debug_mode_active"><input name="nb_debug_mode_active" type="checkbox" id="nb_debug_mode_active" value="on" <?php checked( $nb_debug_mode_opt_val, 'on' ); ?>>
|
||||
<?php _e('Activate the debug mode when customizing', 'text_doma'); ?></label>
|
||||
<p class="description"><?php _e('In debug mode, during customization Nimble Builder deactivates all modules content and prints only the structure of your sections. This lets you troubleshoot, remove or edit your modules safely.', 'text_doma'); ?></p>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
do_action('nb_admin_options_tab_after_content');
|
||||
wp_nonce_field( 'nb-base-options', 'nb-base-options-nonce' );
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
<hr/>
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Remove all Nimble Builder data', 'text_doma'); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php _e('Remove all Nimble Builder data', 'text_doma'); ?></span></legend>
|
||||
<?php
|
||||
$refresh_url = add_query_arg( array( 'tab' => 'options', 'clean_nb' => 'true' ), admin_url( NIMBLE_OPTIONS_PAGE_URL ));
|
||||
ob_start();
|
||||
?>
|
||||
var nb_toggle_clean_button = function() {
|
||||
jQuery( function($) {
|
||||
$('.nb-clean-traces-confirm').stop().slideToggle('fast');
|
||||
});
|
||||
};
|
||||
var _nonce_value, _url
|
||||
var nb_refresh_opt_page = function() {
|
||||
jQuery( function($) {
|
||||
_nonce_value = $('#nb-base-options-nonce').val();
|
||||
_url = '<?php echo esc_url($refresh_url); ?>';
|
||||
// add nonce as param so NB can verify it when the page reloads
|
||||
if ( _nonce_value ) {
|
||||
_url = _url + '&ecnon=' + _nonce_value;// looks like site.com/wp-admin/options-general.php?page=nb-options&tab=options&clean_nb=true&ecnon=7cc5758b65
|
||||
}
|
||||
window.location.href = _url;
|
||||
});
|
||||
};
|
||||
<?php
|
||||
$script = ob_get_clean();
|
||||
wp_register_script( 'nb_options_js', '');
|
||||
wp_enqueue_script( 'nb_options_js' );
|
||||
wp_add_inline_script( 'nb_options_js', $script );
|
||||
?>
|
||||
<?php $clean_nb = isset( $_GET['clean_nb'] ) ? sanitize_text_field($_GET['clean_nb']) : false; ?>
|
||||
<?php if ( $clean_nb ) : ?>
|
||||
<?php $status = sek_clean_all_nimble_data(); ?>
|
||||
<?php if ( 'success' === $status ) : ?>
|
||||
<div id="message" class="updated notice">
|
||||
<p class="nb-clean-traces-success"><strong><?php _e('All Nimble Builder data have been successfully removed from your WordPress website.', 'text_doma'); ?></strong></p>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div id="message" class="error notice">
|
||||
<p><strong><?php _e('Security problem when trying to remove Nimble Builder data.', 'text_doma'); ?></strong></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<p class="description"><?php _e('This will permanently remove all data created by Nimble Builder and stored in your database or as stylesheets : page customizations, custom sections, custom templates, options, CSS stylesheets.', 'text_doma'); ?></p><br/>
|
||||
<button class="button" onclick="window.nb_toggle_clean_button()"><?php _e('Remove now', 'text_doma'); ?></button>
|
||||
<div class="nb-clean-traces-confirm" style="display:none">
|
||||
<p class="description"><?php _e('Once you delete Nimble Builder data, there is no going back. Please be certain. ', 'text_doma'); ?></p><br/>
|
||||
<button class="button nb-permanent-removal-btn" onclick="window.nb_refresh_opt_page()"><?php _e('Yes I want to clean all data', 'text_doma'); ?></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
add_action( 'nb_admin_post', '\Nimble\nb_save_base_options' );
|
||||
// hook : nb_admin_post
|
||||
function nb_save_base_options() {
|
||||
// First, validate the nonce and verify the user as permission to save.
|
||||
if ( !nb_has_valid_nonce( 'nb-base-options', 'nb-base-options-nonce' ) || !current_user_can( 'manage_options' ) )
|
||||
return;
|
||||
|
||||
// Shortcode parsing when customizing
|
||||
nb_maybe_update_checkbox_option( NIMBLE_OPT_NAME_FOR_SHORTCODE_PARSING, 'off' );
|
||||
// Widgets disabled when customizing
|
||||
nb_maybe_update_checkbox_option( NIMBLE_OPT_NAME_FOR_DISABLING_WIDGET_MODULE, 'off' );
|
||||
// Debug mode
|
||||
nb_maybe_update_checkbox_option( NIMBLE_OPT_NAME_FOR_DEBUG_MODE, 'off' );
|
||||
}
|
||||
|
||||
// helper to update a checkbox option
|
||||
// the option is updated only if different than the default val or if the option exists already
|
||||
function nb_maybe_update_checkbox_option( $opt_name, $unchecked_value ) {
|
||||
$opt_value = get_option( $opt_name );
|
||||
$posted_value = array_key_exists( $opt_name, $_POST ) ? sanitize_text_field($_POST[$opt_name]) : $unchecked_value;
|
||||
if ( $unchecked_value !== $posted_value ) {
|
||||
update_option( $opt_name, esc_attr( $posted_value ), 'no' );
|
||||
} else {
|
||||
// if the option was never set before, then leave it not set
|
||||
// otherwise update it to 'off'
|
||||
if ( false !== $opt_value ) {
|
||||
update_option( $opt_name, $unchecked_value, 'no' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action('nb_base_admin_options_registered');
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* RESTRICT USERS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
//register option tab and print the form
|
||||
if ( sek_is_pro() || sek_is_upsell_enabled() ) {
|
||||
$restrict_users_title = __('Manage authorized users', 'text-doma');
|
||||
if ( !sek_is_pro() ) {
|
||||
$restrict_users_title = sprintf( '<span class="sek-pro-icon"><img src="%1$s" alt="Pro feature"></span><span class="sek-title-after-icon">%2$s</span>',
|
||||
NIMBLE_BASE_URL.'/assets/czr/sek/img/pro_orange.svg?ver='.NIMBLE_VERSION,
|
||||
__('Manage authorized users', 'nimble' )
|
||||
);
|
||||
}
|
||||
nb_register_option_tab([
|
||||
'id' => 'restrict_users',
|
||||
'title' => $restrict_users_title,
|
||||
'page_title' => __('Manage authorized users', 'nimble' ),
|
||||
'content' => '\Nimble\print_restrict_users_options_content',
|
||||
]);
|
||||
|
||||
function print_restrict_users_options_content() {
|
||||
if ( !sek_is_pro() ) {
|
||||
?>
|
||||
<h4><?php _e('Nimble Builder can be used by default by all users with an administrator role. With Nimble Builder Pro you can decide which administrators are allowed to use the plugin.', 'text_domain'); ?></h4>
|
||||
<h4><?php _e('Unauthorized users will not see any reference to Nimble Builder when editing a page, in the customizer and in the WordPress admin screens.', 'text_domain') ?></h4>
|
||||
<a class="sek-pro-link" href="https://presscustomizr.com/nimble-builder-pro/" rel="noopener noreferrer" title="Go Pro" target="_blank"><?php _e('Go Pro', 'text_domain'); ?> <span class="dashicons dashicons-external"></span></a>
|
||||
<?php
|
||||
}
|
||||
do_action( 'nb_restrict_user_content' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* SYSTEM INFO
|
||||
/* ------------------------------------------------------------------------- */
|
||||
nb_register_option_tab([
|
||||
'id' => 'system-info',
|
||||
'title' => __('System info', 'text-doma'),
|
||||
'page_title' => __('System info', 'nimble' ),
|
||||
'content' => '\Nimble\print_system_info',
|
||||
]);
|
||||
function print_system_info() {
|
||||
require_once( NIMBLE_BASE_PATH . '/inc/admin/system-info.php' );
|
||||
?>
|
||||
<h3><?php _e( 'System Informations', 'text_domain_to_be_chg' ); ?></h3>
|
||||
<h4><?php _e( 'Please include your system informations when posting support requests.' , 'text_domain_to_be_chg' ) ?></h4>
|
||||
<textarea readonly="readonly" onclick="this.focus();this.select()" id="system-info-textarea" name="tc-sysinfo" title="<?php _e( 'To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'text_domain_to_be_chg' ); ?>" style="width: 800px;min-height: 800px;font-family: Menlo,Monaco,monospace;background: 0 0;white-space: pre;overflow: auto;display:block;"><?php echo wp_kses_post(sek_config_infos()); ?></textarea>
|
||||
<?php
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* DOCUMENTATION
|
||||
/* ------------------------------------------------------------------------- */
|
||||
nb_register_option_tab([
|
||||
'id' => 'doc',
|
||||
'title' => __('Documentation', 'text-doma'),
|
||||
'page_title' => __('Nimble Builder knowledge base', 'nimble' ),
|
||||
'content' => '\Nimble\print_doc_page',
|
||||
]);
|
||||
function print_doc_page() {
|
||||
?>
|
||||
<div class="nimble-doc">
|
||||
<ul>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/337-getting-started-with-the-nimble-builder-plugin"><span>Getting started with Nimble Page Builder for WordPress</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/386-how-to-access-the-live-customization-interface-of-the-nimble-builder"><span>How to access the live customization interface of Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/371-how-to-start-building-from-a-blank-page-with-the-wordpress-nimble-builder"><span>How to start building from a blank ( full width ) page with WordPress Nimble Builder?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href=" https://docs.presscustomizr.com/article/427-how-to-insert-and-edit-a-module-with-nimble-builder"><span>How to insert and edit a module with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/358-building-your-header-and-footer-with-the-nimble-builder"><span>How to build your WordPress header and footer with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/350-how-to-use-shortcodes-from-other-plugins-with-the-nimble-builder-plugin"><span>How to embed WordPress shortcodes in your pages with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/366-how-to-add-an-anchor-to-a-section-and-integrate-it-into-the-menu-with-the-nimble-page-builder"><span>How to add an anchor to a section and integrate it into the menu with Nimble Page Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/380-how-to-set-a-parallax-background-for-a-section-in-wordpress-with-the-nimble-builder"><span>How to set a parallax background for a section in WordPress with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/343-designing-for-mobile-devices-with-wordpress-nimble-builder"><span>Designing for mobile devices with the WordPress Nimble Builder</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/414-nimble-builder-and-website-performances"><span>Nimble Builder and website performance 🚀</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/393-how-to-add-post-grids-to-any-wordpress-page-with-nimble-builder"><span>How to add post grids to any WordPress page with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/372-design-your-404-page-with-the-nimble-builder"><span>How to design your 404 error page with Nimble Builder</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/391-how-to-export-and-import-templates-with-nimble-builder"><span>How to reuse sections and templates with the export / import feature of Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/401-how-to-create-a-video-background-with-nimble-builder-wordpress-plugin"><span>How to create a video background with Nimble Builder WordPress plugin ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/408-how-to-insert-a-responsive-carousel-in-your-wordpress-pages-with-nimble-builder"><span>How to insert a responsive carousel in your WordPress pages with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/389-how-to-visualize-the-structure-of-the-content-created-with-nimble-builder"><span>How to visualize the structure of the content created with Nimble Builder ?</span></a></li>
|
||||
<li><a target="_blank" rel="noopener noreferrer" href="https://docs.presscustomizr.com/article/383-how-to-customize-the-height-of-your-sections-and-columns-with-the-nimble-builder"><span>How to customize the height of your sections and columns with Nimble Builder ?</span></a></li>
|
||||
|
||||
</ul>
|
||||
<a href="https://docs.presscustomizr.com/collection/334-nimble-page-builder" target="_blank" class="button button-primary button-hero" rel="noopener noreferrer"><span class="dashicons dashicons-search"></span> <?php _e('Explore Nimble Builder knowledge base', 'text-doma'); ?></a>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
namespace Nimble;
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Get system info
|
||||
* Inspired by the system infos page for Easy Digital Download plugin
|
||||
* @return string $return A string containing the info to output
|
||||
*/
|
||||
function sek_config_infos() {
|
||||
global $wpdb;
|
||||
|
||||
if ( !class_exists( 'Browser' ) ) {
|
||||
require_once( NIMBLE_BASE_PATH . '/inc/libs/browser.php' );
|
||||
}
|
||||
|
||||
$browser = new \Browser();
|
||||
|
||||
// Get theme info
|
||||
$theme_data = wp_get_theme();
|
||||
$theme = $theme_data->Name . ' ' . $theme_data->Version;
|
||||
$parent_theme = $theme_data->Template;
|
||||
if ( !empty( $parent_theme ) ) {
|
||||
$parent_theme_data = wp_get_theme( $parent_theme );
|
||||
$parent_theme = $parent_theme_data->Name . ' ' . $parent_theme_data->Version;
|
||||
}
|
||||
|
||||
$return = '### Begin System Info (Generated ' . date( 'Y-m-d H:i:s' ) . ') ###' . "";
|
||||
|
||||
// Site infos
|
||||
$return .= "\n" .'------------ SITE INFO' . "\n";
|
||||
$return .= 'Site URL: ' . site_url() . "\n";
|
||||
$return .= 'Home URL: ' . home_url() . "\n";
|
||||
$return .= 'Multisite: ' . ( is_multisite() ? 'Yes' : 'No' ) . "\n";
|
||||
|
||||
// Browser infos
|
||||
$return .= "\n\n" . '------------ USER BROWSER' . "\n";
|
||||
$return .= $browser;
|
||||
|
||||
$locale = get_locale();
|
||||
|
||||
// WordPress config
|
||||
$return .= "\n\n" . '------------ WORDPRESS CONFIG' . "\n";
|
||||
$return .= 'WP Version: ' . get_bloginfo( 'version' ) . "\n";
|
||||
$return .= 'Language: ' . ( !empty( $locale ) ? $locale : 'en_US' ) . "\n";
|
||||
$return .= 'Permalink Structure: ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . "\n";
|
||||
$return .= 'Active Theme: ' . $theme . "\n";
|
||||
if ( $parent_theme !== $theme ) {
|
||||
$return .= 'Parent Theme: ' . $parent_theme . "\n";
|
||||
}
|
||||
$return .= 'Show On Front: ' . get_option( 'show_on_front' ) . "\n";
|
||||
|
||||
// Only show page specs if frontpage is set to 'page'
|
||||
if( get_option( 'show_on_front' ) == 'page' ) {
|
||||
$front_page_id = get_option( 'page_on_front' );
|
||||
$blog_page_id = get_option( 'page_for_posts' );
|
||||
|
||||
$return .= 'Page On Front: ' . ( $front_page_id != 0 ? get_the_title( $front_page_id ) . ' (#' . $front_page_id . ')' : 'Unset' ) . "\n";
|
||||
$return .= 'Page For Posts: ' . ( $blog_page_id != 0 ? get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' : 'Unset' ) . "\n";
|
||||
}
|
||||
|
||||
$return .= 'ABSPATH: ' . ABSPATH . "\n";
|
||||
|
||||
$return .= 'WP_DEBUG: ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . "\n";
|
||||
$return .= 'WP Memory Limit: ' . ( sek_let_to_num( WP_MEMORY_LIMIT )/( 1024 ) ) ."MB" . "\n";
|
||||
//$return .= 'Registered Post Stati: ' . implode( ', ', get_post_stati() ) . "\n";
|
||||
|
||||
// Nimble configuration
|
||||
$return .= "\n\n" . '------------ NIMBLE CONFIGURATION' . "\n";
|
||||
$return .= 'Version: ' . NIMBLE_VERSION . "\n";
|
||||
$return .= 'Upgraded From: ' . get_option( 'nimble_version_upgraded_from', 'None' ) . "\n";
|
||||
$return .= 'Started With: ' . get_option( 'nimble_started_with_version', 'None' ) . "\n";
|
||||
|
||||
// sept 2020 : filter added to allow printing NB Pro versions info
|
||||
$return = apply_filters('nb_admin_syst_info_after_nb_config', $return);
|
||||
|
||||
// Get plugins that have an update
|
||||
$updates = get_plugin_updates();
|
||||
|
||||
// Must-use plugins
|
||||
// NOTE: MU plugins can't show updates!
|
||||
$muplugins = get_mu_plugins();
|
||||
if( count( $muplugins ) > 0 ) {
|
||||
$return .= "\n\n" . '------------ MU PLUGINS' . "\n";
|
||||
|
||||
foreach( $muplugins as $plugin => $plugin_data ) {
|
||||
$return .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// WordPress active plugins
|
||||
$return .= "\n\n" . '------------ WP ACTIVE PLUGINS' . "\n";
|
||||
|
||||
$plugins = get_plugins();
|
||||
$active_plugins = get_option( 'active_plugins', array() );
|
||||
|
||||
foreach( $plugins as $plugin_path => $plugin ) {
|
||||
if( !in_array( $plugin_path, $active_plugins ) )
|
||||
continue;
|
||||
|
||||
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '';
|
||||
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
|
||||
}
|
||||
|
||||
// WordPress inactive plugins
|
||||
$return .= "\n\n" . '------------ WP INACTIVE PLUGINS' . "\n";
|
||||
|
||||
foreach( $plugins as $plugin_path => $plugin ) {
|
||||
if( in_array( $plugin_path, $active_plugins ) )
|
||||
continue;
|
||||
|
||||
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '';
|
||||
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
|
||||
}
|
||||
|
||||
if( is_multisite() ) {
|
||||
// WordPress Multisite active plugins
|
||||
$return .= "\n\n" . '------------ NETWORK ACTIVE PLUGINS' . "\n";
|
||||
|
||||
$plugins = wp_get_active_network_plugins();
|
||||
$active_plugins = get_site_option( 'active_sitewide_plugins', array() );
|
||||
|
||||
foreach( $plugins as $plugin_path ) {
|
||||
$plugin_base = plugin_basename( $plugin_path );
|
||||
|
||||
if( !array_key_exists( $plugin_base, $active_plugins ) )
|
||||
continue;
|
||||
|
||||
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '';
|
||||
$plugin = get_plugin_data( $plugin_path );
|
||||
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Server configuration
|
||||
$return .= "\n\n" . '------------ WEBSERVER CONFIG' . "\n";
|
||||
$return .= 'PHP Version: ' . PHP_VERSION . "\n";
|
||||
$return .= 'MySQL Version: ' . $wpdb->db_version() . "\n";
|
||||
$return .= 'Webserver Info: ' . sanitize_text_field($_SERVER['SERVER_SOFTWARE']) . "\n";
|
||||
$return .= 'Write/Read permissions: ' . sek_get_write_permissions_status() . "\n";
|
||||
|
||||
// PHP configs
|
||||
$return .= "\n\n" . '------------ PHP CONFIG' . "\n";
|
||||
$return .= 'Memory Limit: ' . ini_get( 'memory_limit' ) . "\n";
|
||||
$return .= 'Upload Max Size: ' . ini_get( 'upload_max_filesize' ) . "\n";
|
||||
$return .= 'Post Max Size: ' . ini_get( 'post_max_size' ) . "\n";
|
||||
$return .= 'Upload Max Filesize: ' . ini_get( 'upload_max_filesize' ) . "\n";
|
||||
$return .= 'Time Limit: ' . ini_get( 'max_execution_time' ) . "\n";
|
||||
$return .= 'Max Input Vars: ' . ini_get( 'max_input_vars' ) . "\n";
|
||||
$return .= 'Display Errors: ' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ) . "\n";
|
||||
$return .= 'PHP Arg Separator: ' . ini_get( 'arg_separator.output' ) . "\n";
|
||||
$return .= 'PHP Allow URL File Open: ' . ini_get( 'allow_url_fopen' ) . "\n";
|
||||
|
||||
// PHP extensions and such
|
||||
// $return .= "\n\n" . '------------ PHP EXTENSIONS' . "\n";
|
||||
// $return .= 'cURL: ' . ( function_exists( 'curl_init' ) ? 'Supported' : 'Not Supported' ) . "\n";
|
||||
// $return .= 'fsockopen: ' . ( function_exists( 'fsockopen' ) ? 'Supported' : 'Not Supported' ) . "\n";
|
||||
// $return .= 'SOAP Client: ' . ( class_exists( 'SoapClient' ) ? 'Installed' : 'Not Installed' ) . "\n";
|
||||
// $return .= 'Suhosin: ' . ( extension_loaded( 'suhosin' ) ? 'Installed' : 'Not Installed' ) . "\n";
|
||||
|
||||
$return .= "\n\n" . '### End System Info ###';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does Size Conversions
|
||||
*/
|
||||
function sek_let_to_num( $v ) {
|
||||
$l = substr( $v, -1 );
|
||||
$ret = substr( $v, 0, -1 );
|
||||
|
||||
switch ( strtoupper( $l ) ) {
|
||||
case 'P': // fall-through
|
||||
case 'T': // fall-through
|
||||
case 'G': // fall-through
|
||||
case 'M': // fall-through
|
||||
case 'K': // fall-through
|
||||
$ret *= 1024;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function sek_get_write_permissions_status() {
|
||||
$permission_issues = array();
|
||||
$writing_path_candidates = array();
|
||||
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
if ( $wp_upload_dir['error'] ) {
|
||||
$permission_issues[] = 'WordPress root uploads folder';
|
||||
}
|
||||
|
||||
$nimble_css_folder_path = $wp_upload_dir['basedir'] . '/' . NIMBLE_CSS_FOLDER_NAME;
|
||||
|
||||
if ( is_dir( $nimble_css_folder_path ) ) {
|
||||
$writing_path_candidates[ $nimble_css_folder_path ] = 'Nimble uploads folder';
|
||||
}
|
||||
$writing_path_candidates[ ABSPATH ] = 'WP root directory';
|
||||
|
||||
foreach ( $writing_path_candidates as $dir => $description ) {
|
||||
if ( !is_writable( $dir ) ) {
|
||||
$permission_issues[] = $description;
|
||||
}
|
||||
}
|
||||
|
||||
// oct 2020, for https://github.com/presscustomizr/nimble-builder/issues/749
|
||||
$base_module_css_uri = NIMBLE_BASE_PATH . '/assets/front/css/modules/';
|
||||
if ( !is_readable($base_module_css_uri) ) {
|
||||
$permission_issues[] = 'module css folder not readable';
|
||||
}
|
||||
|
||||
if ( $permission_issues ) {
|
||||
$message = 'NOK => issues with : ';
|
||||
$message .= implode( ' and ', $permission_issues );
|
||||
} else {
|
||||
$message = 'OK';
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user