get_col($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key LIKE %s", '_sidebars_widgets')); if (!empty($post_ids)) { foreach ($post_ids as $post_id) { update_post_meta($post_id, '_customize_sidebars', 'yes'); } } $upgraded = true; } if (version_compare($current_version, '2.5', '<')) { // do nothing $upgraded = true; } if ($upgraded) { update_option('page_widget_version', PAGE_WIDGET_VERSION); } } function pw_print_script_template() { global $pagenow, $typenow; if (pw_backend_check_allow_continue_process()) { do_action('admin_footer-widgets.php'); } } function pw_print_scripts() { global $pagenow, $typenow; if (pw_backend_check_allow_continue_process()) { /* Plugin support */ // Image widget support if (is_plugin_active('image-widget/image-widget.php')) { wp_enqueue_script('tribe-image-widget', WP_PLUGIN_URL . '/image-widget/resources/js/image-widget.js', array('jquery', 'media-upload', 'media-views'), false, true); wp_localize_script( 'tribe-image-widget', 'TribeImageWidget', array( 'frame_title' => __( 'Select an Image', 'image_widget' ), 'button_title' => __( 'Insert Into Widget', 'image_widget' ), ) ); } // Simple Link List Widget plugin support/ if (is_plugin_active('simple-link-list-widget/simple-link-list-widget.php')) { wp_enqueue_script( 'sllw-sort-js', WP_PLUGIN_URL .'/simple-link-list-widget/js/sllw-sort.js'); } // Easy releated posts and Simple social icons support. if ( is_plugin_active('easy-related-posts/easy_related_posts.php') || is_plugin_active('simple-social-icons/simple-social-icons.php') ) { wp_enqueue_script( 'wp-color-picker'); } wp_enqueue_script('pw-widgets', plugin_dir_url(__FILE__) . 'assets/js/page-widgets.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'), rand(), true); /* * Add pwTextWidgets extend from wp.textWidgets * Add pwMediaWidgets extend from wp.mediaWidgets */ if( version_compare( get_bloginfo('version'), '4.7.9', '>' ) ) { do_action( 'admin_print_scripts-widgets.php' ); wp_enqueue_script('pw-extend-text-widgets', plugin_dir_url(__FILE__) . 'assets/js/pw-text-widgets-extend-wp-text-widgets.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'), PAGE_WIDGET_VERSION, true); wp_enqueue_script('pw-extend-media-widgets', plugin_dir_url(__FILE__) . 'assets/js/pw-media-widgets-extend-wp-media-widgets.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'), PAGE_WIDGET_VERSION, true); } /* * Add pwCustomHTML extend from wp.customHtmlWidgets */ if( version_compare( get_bloginfo('version'), '4.8.5', '>' ) ) { wp_enqueue_script('pw-extend-custom-html', plugin_dir_url(__FILE__) . 'assets/js/pw-custom-html-extend-wp-custom-html.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'), PAGE_WIDGET_VERSION, true); $settings = wp_enqueue_code_editor( array( 'type' => 'text/html', 'codemirror' => array( 'indentUnit' => 2, 'tabSize' => 2, ), )); if ( empty( $settings ) ) { $settings = array( 'disabled' => true, ); } wp_add_inline_script( 'pw-extend-custom-html', sprintf( 'pwCustomHTML.init( %s );', wp_json_encode( $settings ) ), 'after' ); } wp_localize_script( 'pw-widgets', 'wp_page_widgets', array( 'remove_inactive_widgets_text' => __('Press the following button will remove all of these inactive widgets', 'wp-page-widgets'), 'remove_inactive_widgets' => __( 'Remove inactive widgets', 'wp-page-widgets' ), ) ); } } function pw_print_styles() { global $pagenow, $typenow; if (pw_backend_check_allow_continue_process()) { if (is_plugin_active('custom-field-list-widget/widget_custom_field_list.php')) { wp_enqueue_style('pw-widgets3', WP_PLUGIN_URL . '/custom-field-list-widget/widget_custom_field_list_widgetsettings.css', array()); } // Simple Link List Widget plugin support if (is_plugin_active('simple-link-list-widget/simple-link-list-widget.php')) { wp_enqueue_style( 'sllw-css', WP_PLUGIN_URL .'/simple-link-list-widget/css/sllw.css'); } if ( version_compare( get_bloginfo('version'), '3.8', '<' ) ) { wp_enqueue_style('pw-widgets', plugin_dir_url(__FILE__) . 'assets/css/page-widgets.css', array(), PAGE_WIDGET_VERSION); } } if ( version_compare( get_bloginfo('version'), '3.8', '<' ) ) { wp_enqueue_style('pw-style', plugin_dir_url(__FILE__) . 'assets/css/style.css', array(), PAGE_WIDGET_VERSION); } else { wp_enqueue_style('pw-style', plugin_dir_url(__FILE__) . 'assets/css/style-3.8.css', array(), PAGE_WIDGET_VERSION); } } function pw_admin_menu() { // check user capability (only allow Editor or above to customize Widgets global $typenow, $pagenow; $settings = pw_get_settings(); if (current_user_can('edit_posts')) { // add Page Widgets metabox $typesEnabled = pw_get_posts_taxnomies_enabled_from_settings($settings); foreach ($typesEnabled['posts'] as $post_type) { add_meta_box('pw-widgets', __('Page Widgets', 'wp-page-widgets'), 'pw_metabox_content', $post_type, 'advanced', 'high'); } foreach ($typesEnabled['taxonomies'] as $taxonomy) { if (!empty($typenow) && !empty($pagenow)) { if ($pagenow == "term.php" && in_array($typenow, $typesEnabled['posts'])) { add_action($taxonomy . '_edit_form', 'pw_showTaxonomyWidget', 99, 2); } } } //add Taxonomy Widgets metabox /*foreach ($settings['taxonomies'] as $taxonomy) { add_action($taxonomy . '_edit_form', 'pw_showTaxonomyWidget', 99, 2); }*/ } // options page // add_options_page('Page Widgets', 'Page Widgets', 'manage_options', 'pw-settings', 'pw_settings_page'); // Menu page //add_menu_page('Page Widgets', __('Page Widgets', 'wp-page-widgets'), 'manage_options', 'pw-settings', 'pw_settings_page'); // Add a submenu to the custom top-level menu: front page //add_submenu_page('pw-settings', 'Front page', 'Front page', 'manage_options', 'pw-front-page', 'pw_front_page'); // Add a submenu to the custom top-level menu: search page //add_submenu_page('pw-settings', __('Search page', 'wp-page-widgets'), __('Search page', 'wp-page-widgets'), 'manage_options', 'pw-search-page', 'pw_search_page'); add_submenu_page('options-general.php', __('Page widgets settings', 'wp-page-widgets'), __('Page widgets settings', 'wp-page-widgets'), 'manage_options', 'pw-settings', 'pw_settings_page'); add_submenu_page('options-general.php', __('Search page widgets', 'wp-page-widgets'), __('Search page widgets', 'wp-page-widgets'), 'manage_options', 'pw-search-page', 'pw_search_page'); } function pw_settings_page() { global $wp_registered_sidebars; if (isset($_POST['save-changes'])) { $opts = stripslashes_deep($_POST['pw_opts']); update_option('pw_options', $opts); echo '
'.__('Saved Changes', 'wp-page-widgets').'
'.__('Thank you for using this plugin. If you appreciate our works, please consider to', 'wp-page-widgets').' '.__('donate us', 'wp-page-widgets').'. '.__('With your help, we can continue supporting and developing this plugin.', 'wp-page-widgets').'
'.__('Hide this donation message', 'wp-page-widgets').'.
'.__('Thank you for using this plugin. If you appreciate our works, please consider to', 'wp-page-widgets').' '.__('donate us', 'wp-page-widgets').'. '.__('With your help, we can continue supporting and developing this plugin.', 'wp-page-widgets').'
'.__('Hide this donation message', 'wp-page-widgets').'.
'.__('Thank you for using this plugin. If you appreciate our works, please consider to', 'wp-page-widgets').' '.__('donate us', 'wp-page-widgets').'. '.__('With your help, we can continue supporting and developing this plugin.', 'wp-page-widgets').'
'.__('Hide this donation message', 'wp-page-widgets').'.
'.__('Thank you for using this plugin. If you appreciate our works, please consider to', 'wp-page-widgets').' '.__('donate us', 'wp-page-widgets').'. '.__('With your help, we can continue supporting and developing this plugin.', 'wp-page-widgets').'
'.__('Hide this donation message', 'wp-page-widgets').'.
' . __('An error has occured. Please reload the page and try again.') . '
'; $sidebars = wp_get_sidebars_widgets(); $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array(); // delete if (isset($_POST['delete_widget']) && $_POST['delete_widget']) { if (!isset($wp_registered_widgets[$widget_id])) die($error); $sidebar = array_diff($sidebar, array($widget_id)); $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); } elseif ($settings && preg_match('/__i__|%i%/', key($settings))) { if (!$multi_number) die($error); $_POST['widget-' . $id_base] = array($multi_number => array_shift($settings)); $widget_id = $id_base . '-' . $multi_number; $sidebar[] = $widget_id; } $_POST['widget-id'] = $sidebar; // Save widgets //var_dump(isset($_POST)); if (!isset($_POST['delete_widget']) || !$_POST['delete_widget']) { //if (!isset($_POST['delete_widget']) && !$_POST['delete_widget']) { foreach ((array) $wp_registered_widget_updates as $name => $control) { if ($name == $id_base) { if (!is_callable($control['callback'])) continue; // do some hack $number = $multi_number > 0 ? $multi_number : (int) $_POST['widget_number']; if (is_object($control['callback'][0])) { $all_instance = $control['callback'][0]->get_settings(); } if (!isset($all_instance[$number])) { // that's mean new widget was added. => call update function to add widget (globally). ob_start(); call_user_func_array($control['callback'], $control['params']); ob_end_clean(); } else { // mean existing widget was saved. => save separate settings for each post (avoid to overwrite global existing widget data. $widget_obj = &$control['callback'][0]; if (!empty($post_id)) { $widget_obj->option_name = 'widget_' . $post_id . '_' . $widget_obj->id_base; } else if (!empty($search_page)) { $widget_obj->option_name = 'widget_search_' . $widget_obj->id_base; } else { $optionName = $taxonomy . '_widget_' . $tag_id . '_' . $widget_obj->id_base; $widget_obj->option_name = $optionName; } ob_start(); call_user_func_array($control['callback'], $control['params']); ob_end_clean(); } break; } } } if (isset($_POST['delete_widget']) && $_POST['delete_widget']) { $sidebars[$sidebar_id] = $sidebar; if (!empty($post_id)) { pw_set_sidebars_widgets($sidebars, $post_id); } else if (!empty($search_page)) { pw_set_sidebars_widgets($sidebars, NULL, NULL, 'search_page'); } else { pw_set_sidebars_widgets($sidebars, $tag_id, $taxonomy); } // echo "deleted:$widget_id"; die(); } if (!empty($_POST['add_new'])) die(); if ($form = $wp_registered_widget_controls[$widget_id]) call_user_func_array($form['callback'], $form['params']); print 'Updated ajax save widget.'; if ( function_exists( 'w3tc_pgcache_flush' ) ) { w3tc_pgcache_flush(); } die(); } function pw_set_sidebars_widgets($sidebars_widgets, $post_id, $taxonomy = "", $search_page = NULL) { if (!isset($sidebars_widgets['array_version'])) $sidebars_widgets['array_version'] = 3; // Search page if ($search_page == 'search_page') { update_option('_search_page_sidebars_widgets', $sidebars_widgets); } // For post page elseif (empty($taxonomy)) { update_post_meta($post_id, '_sidebars_widgets', $sidebars_widgets); } // Taxonomy page else { $taxonomyData = getTaxonomyMetaData($taxonomy, $post_id); $taxonomyData['_sidebars_widgets'] = $sidebars_widgets; updateTaxonomiesMetaData($taxonomy, $post_id, $taxonomyData); } } function pw_filter_widgets($sidebars_widgets) { global $post, $pagenow; $objTaxonomy = getTaxonomyAccess(); $typesEnabled = pw_get_posts_taxnomies_enabled_from_settings(); if ( (is_admin() && !pw_backend_check_allow_continue_process()) || (!is_admin() && !is_singular() && !is_search() && empty($objTaxonomy['taxonomy'])) ) { return $sidebars_widgets; } // Search page if (is_search() || (is_admin() && (isset($_GET['page']) && $_GET['page'] == 'pw-search-page'))) { $enable_customize = get_option('_pw_search_page', true); $_sidebars_widgets = get_option('_search_page_sidebars_widgets', true); } // Post page elseif (empty($objTaxonomy['taxonomy'])) { if (empty($typesEnabled['posts'])) { return $sidebars_widgets; } //if admin alway use query string post = ID //Fix conflic when other plugins use query post after load editing post! if ( is_object($post) && isset($_GET['post']) ) { $postID = $_GET['post']; } if (is_admin() && isset($postID)) { if ( !is_object($post) ) $post = new stdClass(); $post->ID = $postID; } if (isset($post->ID)) { $postGet = get_post($post->ID); if (empty($typesEnabled['posts'][$postGet->post_type])) { return $sidebars_widgets; } $enable_customize = get_post_meta($post->ID, '_customize_sidebars', true); $_sidebars_widgets = get_post_meta($post->ID, '_sidebars_widgets', true); } } // Taxonomy page else { if (empty($typesEnabled['taxonomies']) || empty($typesEnabled['taxonomies'][$objTaxonomy['taxonomy']])) { return $sidebars_widgets; } $taxonomyMetaData = getTaxonomyMetaData($objTaxonomy['taxonomy'], $objTaxonomy['term_id']); $enable_customize = $taxonomyMetaData['_customize_sidebars']; $_sidebars_widgets = $taxonomyMetaData['_sidebars_widgets']; } if (isset($enable_customize) && $enable_customize == 'yes' && !empty($_sidebars_widgets)) { if (is_array($_sidebars_widgets) && isset($_sidebars_widgets['array_version'])) unset($_sidebars_widgets['array_version']); $sidebars_widgets = wp_parse_args($_sidebars_widgets, $sidebars_widgets); } return $sidebars_widgets; } function pw_filter_widget_display_instance($instance, $widget, $args) { $widget_instance = getWidgetOptionFE($widget->id_base); if ($widget_instance && isset($widget_instance[$widget->number])) $instance = $widget_instance[$widget->number]; //echo ""; print_r($widget_instance); echo ""; return $instance; } function pw_filter_widget_form_instance($instance, $widget) { global $post, $pagenow; //print 'Search'; exit(); $objTaxonomy = getTaxonomyAccess(); //$isTaxonomyEdit = $pagenow == "edit-tags.php"; $isTaxonomyEdit = $pagenow == "term.php"; //$enable_customize = get_post_meta($post->ID, '_customize_sidebars', true); if (pw_backend_check_allow_continue_process()) { // Search page if (in_array($pagenow, array('admin.php')) && (($_GET['page'] == 'pw-front-page') || ($_GET['page'] == 'pw-search-page'))) { $widget_instance = get_option('widget_search_' . $widget->id_base); /* print '
'; var_dump($widget_instance); print ''; exit(); // */ } elseif (!$isTaxonomyEdit) { $widget_instance = get_option('widget_' . $post->ID . '_' . $widget->id_base); } elseif (!empty($objTaxonomy['taxonomy'])) { $widget_instance = get_option($objTaxonomy['taxonomy'] . '_widget_' . $objTaxonomy['term_id'] . '_' . $widget->id_base); } if ($widget_instance && isset($widget_instance[$widget->number])) { $instance = $widget_instance[$widget->number]; } } return $instance; } function sidebar_params( $params ) { global $wp_registered_widgets; $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[ $widget_id ]; $widget_id_base = ""; if(isset($widget_obj['callback']) && is_object($widget_obj['callback'][0])) $widget_id_base = $widget_obj['callback'][0]->id_base; elseif(isset($widget_obj['_callback']) && is_object($widget_obj['_callback'][0])) $widget_id_base = $widget_obj['_callback'][0]->id_base; $widget_num = $widget_obj['params'][0]['number']; if(empty($widget_id_base)) return $params; $widget_opt = getWidgetOptionFE($widget_id_base); if(!empty($widget_opt)){ $widget_extra_classes = ''; if ( isset( $widget_opt[ $widget_num ]['column-classes'] ) && ! empty( $widget_opt[ $widget_num ]['column-classes'] ) ) { $widget_extra_classes .= $widget_opt[ $widget_num ]['column-classes'].' '; } if ( isset( $widget_opt[ $widget_num ]['column-classes-first'] ) && 1 == $widget_opt[ $widget_num ]['column-classes-first'] ) { $widget_extra_classes .= 'first '; } // Remove class added by plugin genesis widget column classes $column_classes = array( 'one-half', 'one-third', 'one-fourth', 'one-sixth', 'two-thirds', 'two-fourths', 'two-sixths', 'three-fourths', 'three-sixths', 'four-sixths', 'five-sixths' ); foreach($column_classes as $class){ $params[0]['before_widget'] = str_replace('class="' . $class, 'class="', $params[0]['before_widget']); } $params[0]['before_widget'] = preg_replace( '/class="/', 'class="'.$widget_extra_classes , $params[0]['before_widget'], 1 ); } return $params; } function getWidgetOptionFE($widget_id_base){ global $post; $widget_opt = array(); $objTaxonomy = getTaxonomyAccess(); if (is_search()) { $enable_customize = get_option('_pw_search_page', true); if ($enable_customize == 'yes') { $widget_instance = get_option('widget_search_' . $widget_id_base); /* print '
'; var_dump($widget->number); var_dump($widget_instance); var_dump($widget_instance[3]); print ''; //exit(); // * */ if ($widget_instance) { $widget_opt = $widget_instance; } } // Use custom widgets for taxonomy page. } elseif (!empty($objTaxonomy['taxonomy'])) { $taxonomy = $objTaxonomy['taxonomy']; $tax_id = $objTaxonomy['term_id']; $taxonomyMetaData = getTaxonomyMetaData($taxonomy, $tax_id); $enable_customize = $taxonomyMetaData['_customize_sidebars']; if ($enable_customize == 'yes') { $widget_instance = get_option($taxonomy . '_widget_' . $tax_id . '_' . $widget_id_base); if ($widget_instance) { $widget_opt = $widget_instance; } } } elseif (!empty($post->ID)) { $enable_customize = get_post_meta($post->ID, '_customize_sidebars', true); if ($enable_customize == 'yes' && is_singular()) { $widget_instance = get_option('widget_' . $post->ID . '_' . $widget_id_base); if ($widget_instance) { $widget_opt = $widget_instance; } } } return $widget_opt; } function getTaxonomyMetaData($taxonomy, $tag_id) { $taxonomiesMetaData = getTaxonomiesMetaData($taxonomy); $taxonomyData = isset($taxonomiesMetaData[$tag_id]) ? $taxonomiesMetaData[$tag_id] : array('_customize_sidebars' => "no", '_sidebars_widgets' => array()); $taxonomyData['_customize_sidebars'] = !empty($taxonomyData['_customize_sidebars']) ? $taxonomyData['_customize_sidebars'] : "no"; return $taxonomyData; } function getTaxonomiesMetaData($taxonomy) { $key = "_" . $taxonomy . "_meta_data"; $taxonomiesMetaData = get_option($key); if (empty($taxonomiesMetaData) || !is_array($taxonomiesMetaData)) { $taxonomiesMetaData = array(); } return $taxonomiesMetaData; } function updateTaxonomiesMetaData($taxonomy, $tax_id, $data) { $key = "_" . $taxonomy . "_meta_data"; $taxonomiesMetaData = get_option($key); $taxonomiesMetaData[$tax_id] = $data; update_option($key, $taxonomiesMetaData); } function getTaxonomyAccess() { global $wp_query; $return = array( 'term_id' => "", 'taxonomy' => "" ); if (!is_admin() && (is_tax() || is_tag() || is_category() ) ) { //&& isset($objRequested)) { $objRequested = $wp_query->queried_object; if (isset($objRequested) && is_object($objRequested)) { $return['term_id'] = isset($objRequested->term_id) ? $objRequested->term_id : ""; $return['taxonomy'] = isset($objRequested->taxonomy) ? $objRequested->taxonomy : ""; } } else { $link = $_SERVER['REQUEST_URI']; if (strpos($link, "tag_ID=") !== false && strpos($link, "taxonomy=") !== false) { $term_id = preg_replace("#(.*)tag_ID=([^&]+)(.*)#", "$2", $link); $taxonomy = preg_replace("#(.*)taxonomy=([^&]+)(.*)#", "$2", $link); $return['term_id'] = $term_id; $return['taxonomy'] = $taxonomy; } } return $return; } function pw_backend_check_allow_continue_process() { global $typenow, $pagenow; $typesEnabled = pw_get_posts_taxnomies_enabled_from_settings(); $isSearchConfigPage = !empty($_GET['page']) && $_GET['page'] == 'pw-search-page'; $isEnableFromSetting = false; if (!empty($typenow) && !empty($typesEnabled['posts'])) { $isEnableFromSetting = in_array($typenow, $typesEnabled['posts']); } return $isSearchConfigPage || $isEnableFromSetting; } /* Not need this action http://wordpress.org/support/topic/incompatibility-with-black-studio-tinymce-widget?replies=1 add_action('admin_init', 'pw_admin_head'); function pw_admin_head() { global $pagenow; if ( in_array($pagenow, array('post-new.php', 'post.php')) || (($pagenow == 'edit-tags.php') && isset($_GET['action']) && $_GET['action'] == 'edit') || // Page widget config for front page, search page ( in_array($pagenow, array('admin.php')) && (($_GET['page'] == 'pw-front-page') || ($_GET['page'] == 'pw-search-page')) ) ) { // Compatibility for Black Studio TinyMCE Widget plugin if (is_plugin_active('black-studio-tinymce-widget/black-studio-tinymce-widget.php')) { add_action( 'admin_head', 'black_studio_tinymce_load_tiny_mce'); add_filter( 'tiny_mce_before_init', 'black_studio_tinymce_init_editor', 20); add_action( 'admin_print_scripts', 'black_studio_tinymce_scripts'); add_action( 'admin_print_styles', 'black_studio_tinymce_styles'); add_action( 'admin_print_footer_scripts', 'black_studio_tinymce_footer_scripts'); } } } */