PK ! UH H ! class-custom-sidebars-widgets.phpnu [ singleton. * * @since 2.0 */ private function __construct() { if ( is_admin() ) { add_action( 'widgets_admin_page', array( $this, 'widget_sidebar_content' ) ); add_action( 'admin_head-widgets.php', array( $this, 'init_admin_head' ) ); } add_action( 'widgets_admin_page', array( $this, 'add_div_start' ) ); add_action( 'sidebar_admin_page', array( $this, 'add_div_end' ) ); } public function add_div_start() { echo '
%s
', __( 'After turn on any Custom Taxonomy you need to reload this screen to be able choose it in Sidebar Location.', 'custom-sidebars' ) ); } } return $screen_settings; } /** * Update capabilities select box * * @since 3.0.9 */ public function update_custom_sidebars_metabox_roles() { $this->update_option_field( $this->metabox_roles_name ); } /** * Update custom taxoniomies select box * * @since 3.1.4 */ public function update_custom_sidebars_metabox_custom_taxonomies() { $this->update_option_field( $this->custom_taxonomies_name ); } /** * Helper for update metabox functions. * * @since 3.1.4 */ private function update_option_field( $name ) { /** * check required data */ if ( ! isset( $_REQUEST['_wpnonce'] ) || ! isset( $_REQUEST['fields'] ) ) { wp_send_json_error(); } /** * check nonce value */ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], $name ) ) { wp_send_json_error(); } $value = array(); foreach ( $_REQUEST['fields'] as $role => $status ) { if ( 'true' == $status ) { $value[] = $role; } } $status = add_option( $name, $value, '', 'no' ); if ( ! $status ) { update_option( $name, $value ); } wp_send_json_success(); } /** * Update entry author is allowed to change custom sidebars. * * @since 3.1.5 */ public function update_custom_sidebars_allow_author() { /** * check required data */ if ( ! isset( $_REQUEST['_wpnonce'] ) ) { wp_send_json_error(); } /** * check nonce value */ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], $this->allow_author_name ) ) { wp_send_json_error(); } $value = isset( $_REQUEST['value'] )? 'true' === $_REQUEST['value'] : false; $status = add_option( $this->allow_author_name, $value, '', 'no' ); if ( ! $status ) { update_option( $this->allow_author_name, $value ); } wp_send_json_success(); } /** * Check ability to save sidebars * * @since 3.0.9 */ public function current_user_can_update_custom_sidebars() { $allowed = get_option( $this->metabox_roles_name, 'any' ); if ( is_string( $allowed ) && 'any' == $allowed ) { return true; } else { $current_user = wp_get_current_user(); $current_user_roles = (array) $current_user->roles; foreach ( $allowed as $role ) { if ( in_array( $role, $current_user_roles ) ) { return true; } } } return false; } /** * Get allowed taxoniomies. * * @since 3.1.4 */ public function get_allowed_custom_taxonmies() { $value = get_option( $this->custom_taxonomies_name ); if ( empty( $value ) || ! is_array( $value ) ) { return array(); } return $value; } /** * Check author ability to change sidebars during entry edit * * @since 3.1.5 */ private function check_author_ability_to_replace() { global $post; if ( current_user_can( self::$cap_required ) ) { return true; } $checked = get_option( $this->allow_author_name, false ); if ( $checked ) { if ( current_user_can( 'edit_posts', $post->ID ) ) { return true; } } return false; } }; PK ! d d class-custom-sidebars-export.phpnu [ singleton. * * @since 2.0 */ private function __construct() { add_action( 'admin_init', array( $this, 'admin_init' ) ); } /** * Admin Init * * @since 3.1.6 */ public function admin_init() { add_action( 'cs_widget_header', array( $this, 'widget_header' ) ); add_action( 'cs_ajax_request', array( $this, 'handle_ajax' ) ); } /** * Called by action 'cs_widget_header'. Output the export/import button in * the widget header. * * @since 2.0 */ public function widget_header() { ?> 'ERR', ); $is_json = true; $handle_it = false; $view_file = ''; switch ( $ajax_action ) { case 'export': case 'import': case 'preview-import': $handle_it = true; $req->status = 'OK'; $req->action = $ajax_action; break; } // The ajax request was not meant for us... if ( ! $handle_it ) { return false; } if ( ! current_user_can( self::$cap_required ) ) { $req = self::req_err( $req, __( 'You do not have permission for this', 'custom-sidebars' ) ); } else { switch ( $ajax_action ) { case 'export': $this->download_export_file(); break; case 'preview-import': $req = $this->read_import_file( $req ); if ( 'OK' == $req->status ) { ob_start(); include CSB_VIEWS_DIR . 'import.php'; $req->html = ob_get_clean(); } break; case 'import': $req = $this->prepare_import_data( $req ); break; } } // Make the ajax response either as JSON or plain text. if ( $is_json ) { self::json_response( $req ); } else { ob_start(); include CSB_VIEWS_DIR . $view_file; $resp = ob_get_clean(); self::plain_response( $resp ); } } /*============================*\ ================================ == == == EXPORT == == == ================================ \*============================*/ /** * Collects the plugin details for export. * * @since 2.0 */ private function get_export_data() { global $wp_registered_widgets, $wp_version; $theme = wp_get_theme(); $csb_info = get_plugin_data( CSB_PLUGIN ); $this->version = $csb_info['Version']; $data = array(); // Add some meta-details to the export file. $data['meta'] = array( 'created' => time(), 'wp_version' => $wp_version, 'csb_version' => $csb_info['Version'], 'theme_name' => $theme->get( 'Name' ), 'theme_version' => $theme->get( 'Version' ), 'description' => sanitize_text_field( @$_POST['export-description'] ), ); // Export the custom sidebars. $data['sidebars'] = self::get_custom_sidebars(); // Export the sidebar options (e.g. default replacement). $data['options'] = self::get_options(); // Export category-information. $data['categories'] = get_categories( array( 'hide_empty' => 0 ) ); /* * Export all widget options. * * $wp_registered_widgets contains all widget-instances that were placed * inside a sidebar. So we loop this array and fetch each widgets * options individually: * * Widget options are saved inside options table with option_name * "widget_
',
'
',
"remove_theme_support( 'widgets-block-editor' );
",
);
?>
%2$s