| @@ -1,13 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Initialization Action. | |
| 4 | + * | |
| 5 | + * @package ULTP\Notice | |
| 6 | + * @since v.1.1.0 | |
| 7 | + */ | |
| 2 | 8 | namespace ULTP; |
| 3 | 9 | |
| 4 | 10 | defined('ABSPATH') || exit; |
| 5 | 11 | |
| 6 | -class Initialization{ | |
| 12 | +/** | |
| 13 | + * Initialization class. | |
| 14 | + */ | |
| 15 | +class ULTP_Initialization{ | |
| 7 | 16 | |
| 8 | 17 | private $all_blocks; |
| 9 | 18 | |
| 19 | + /** | |
| 20 | + * Setup class. | |
| 21 | + * | |
| 22 | + * @since v.1.1.0 | |
| 23 | + */ | |
| 10 | 24 | public function __construct(){ |
| 11 | 25 | $this->compatibility_check(); |
| 12 | 26 | $this->requires(); // Include Necessary Files |
| 13 | 27 | $this->blocks(); // Include Blocks |
| @@ -12,10 +26,10 @@ | ||
| 12 | 26 | $this->requires(); // Include Necessary Files |
| 13 | 27 | $this->blocks(); // Include Blocks |
| 14 | 28 | $this->include_addons(); // Include Addons |
| 15 | 29 | |
| 16 | - add_action('wp_head', array($this, 'popular_posts_tracker_callback')); | |
| 17 | - add_filter('block_categories', array($this, 'register_category_callback'), 10, 2); // Block Category Register | |
| 30 | + add_action('wp', array($this, 'popular_posts_tracker_callback')); | |
| 31 | + add_filter('block_categories_all', array($this, 'register_category_callback'), 10, 2); // Block Category Register | |
| 18 | 32 | add_action('after_setup_theme', array($this, 'add_image_size')); |
| 19 | 33 | |
| 20 | 34 | add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor |
| 21 | 35 | add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel |
| @@ -28,16 +42,84 @@ | ||
| 28 | 42 | add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call |
| 29 | 43 | add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User |
| 30 | 44 | add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call |
| 31 | 45 | add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User |
| 32 | - add_action('wp_ajax_ultp_addon', array($this, 'ultp_addon_callback')); // Next Previous AJAX Call | |
| 46 | + add_action('wp_ajax_ultp_addon', array($this, 'ultp_addon_callback')); // Next Previous AJAX Call | |
| 47 | + | |
| 48 | + add_action('admin_init', array($this, 'check_theme_compatibility')); | |
| 49 | + add_action( 'after_switch_theme', array($this, 'wpxpo_swithch_thememe')); | |
| 33 | 50 | } |
| 34 | 51 | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Theme Switch Callback | |
| 55 | + * | |
| 56 | + * @since v.1.1.0 | |
| 57 | + * @return NULL | |
| 58 | + */ | |
| 59 | + public function wpxpo_swithch_thememe () { | |
| 60 | + $this->check_theme_compatibility(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Theme Compatibility Action | |
| 66 | + * | |
| 67 | + * @since v.1.1.0 | |
| 68 | + * @return NULL | |
| 69 | + */ | |
| 70 | + public function check_theme_compatibility() { | |
| 71 | + $licence = apply_filters( 'ultp_theme_integration' , FALSE); | |
| 72 | + $theme = get_transient( 'ulpt_theme_enable' ); | |
| 73 | + | |
| 74 | + if( $licence ) { | |
| 75 | + if( $theme != 'integration' ) { | |
| 76 | + $themes = wp_get_theme(); | |
| 77 | + $api_params = array( | |
| 78 | + 'wpxpo_theme_action' => 'theme_license', | |
| 79 | + 'slug' => $themes->get('TextDomain'), | |
| 80 | + 'author' => $themes->get('Author'), | |
| 81 | + 'item_id' => 181, | |
| 82 | + 'url' => home_url() | |
| 83 | + ); | |
| 84 | + | |
| 85 | + $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); | |
| 86 | + | |
| 87 | + if ( !is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) { | |
| 88 | + $license_data = json_decode( wp_remote_retrieve_body( $response ) ); | |
| 89 | + if(isset($license_data->license)) { | |
| 90 | + if ( $license_data->license == 'valid' ) { | |
| 91 | + set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time | |
| 92 | + } | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + } else { | |
| 97 | + if ( $theme == 'integration' ) { | |
| 98 | + delete_transient('ulpt_theme_enable'); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * Check Compatibility | |
| 106 | + * | |
| 107 | + * @since v.1.0.0 | |
| 108 | + * @return NULL | |
| 109 | + */ | |
| 35 | 110 | public function compatibility_check(){ |
| 36 | 111 | require_once ULTP_PATH.'classes/Compatibility.php'; |
| 37 | 112 | new \ULTP\Compatibility(); |
| 38 | 113 | } |
| 39 | 114 | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Option Panel CSS and JS Scripts | |
| 118 | + * | |
| 119 | + * @since v.1.0.0 | |
| 120 | + * @return NULL | |
| 121 | + */ | |
| 40 | 122 | public function register_scripts_option_panel_callback(){ |
| 41 | 123 | wp_enqueue_style('wp-color-picker'); |
| 42 | 124 | wp_enqueue_script('wp-color-picker'); |
| 43 | 125 | wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true); |
| @@ -42,66 +124,134 @@ | ||
| 42 | 124 | wp_enqueue_script('wp-color-picker'); |
| 43 | 125 | wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true); |
| 44 | 126 | wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER); |
| 45 | 127 | wp_localize_script('ultp-option-script', 'ultp_option_panel', array( |
| 46 | - 'width' => ultimate_post()->get_setting('editor_container'), | |
| 47 | 128 | 'security' => wp_create_nonce('ultp-nonce'), |
| 48 | 129 | 'ajax' => admin_url('admin-ajax.php') |
| 49 | 130 | )); |
| 50 | 131 | } |
| 51 | 132 | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Common Frontend and Backend CSS and JS Scripts | |
| 136 | + * | |
| 137 | + * @since v.1.0.0 | |
| 138 | + * @return NULL | |
| 139 | + */ | |
| 52 | 140 | public function register_scripts_common(){ |
| 53 | - wp_enqueue_style('dashicons'); | |
| 54 | - wp_enqueue_style('ultp-slick-style', ULTP_URL.'assets/css/slick.css', array(), ULTP_VER); | |
| 55 | - wp_enqueue_style('ultp-slick-theme-style', ULTP_URL.'assets/css/slick-theme.css', array(), ULTP_VER); | |
| 56 | - wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/blocks.style.css', array(), ULTP_VER ); | |
| 57 | - if(is_rtl()){ wp_enqueue_style('ultp-blocks-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); } | |
| 58 | - wp_enqueue_script('ultp-flexmenu-script', ULTP_URL.'assets/js/flexmenu.js', array('jquery'), ULTP_VER, true); | |
| 59 | - wp_enqueue_script('ultp-slick-script', ULTP_URL.'assets/js/slick.min.js', array('jquery'), ULTP_VER, true); | |
| 60 | - wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.js', array('jquery','ultp-flexmenu-script'), ULTP_VER, true); | |
| 141 | + wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER ); | |
| 142 | + wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true); | |
| 61 | 143 | wp_localize_script('ultp-script', 'ultp_data_frontend', array( |
| 62 | 144 | 'url' => ULTP_URL, |
| 63 | 145 | 'ajax' => admin_url('admin-ajax.php'), |
| 64 | 146 | 'security' => wp_create_nonce('ultp-nonce') |
| 65 | 147 | )); |
| 148 | + | |
| 66 | 149 | } |
| 67 | 150 | |
| 68 | - // Backend and Frontend Load script | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * Only Frontend CSS and JS Scripts | |
| 154 | + * | |
| 155 | + * @since v.1.0.0 | |
| 156 | + * @return NULL | |
| 157 | + */ | |
| 69 | 158 | public function register_scripts_front_callback() { |
| 70 | - if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) { | |
| 159 | + $call_common = false; | |
| 160 | + if (isset($_GET['preview_id']) && isset($_GET['preview_nonce'])) { | |
| 161 | + $call_common = true; | |
| 71 | 162 | $this->register_scripts_common(); |
| 163 | + } else if ('yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true)) { | |
| 164 | + $call_common = true; | |
| 165 | + $this->register_scripts_common(); | |
| 166 | + } else if (ultimate_post()->is_builder()) { | |
| 167 | + $call_common = true; | |
| 168 | + $this->register_scripts_common(); | |
| 169 | + } else if (apply_filters ('postx_common_script', false)) { | |
| 170 | + $call_common = true; | |
| 171 | + $this->register_scripts_common(); | |
| 72 | 172 | } |
| 173 | + | |
| 174 | + // For WidgetWidget | |
| 175 | + $has_block = false; | |
| 176 | + $widget_blocks = array(); | |
| 177 | + global $wp_registered_sidebars, $sidebars_widgets; | |
| 178 | + foreach ($wp_registered_sidebars as $key => $value) { | |
| 179 | + if (is_active_sidebar($key)) { | |
| 180 | + foreach ($sidebars_widgets[$key] as $val) { | |
| 181 | + if (strpos($val, 'block-') !== false) { | |
| 182 | + if (empty($widget_blocks)) { | |
| 183 | + $widget_blocks = get_option( 'widget_block' ); | |
| 184 | + } | |
| 185 | + foreach ( (array) $widget_blocks as $block ) { | |
| 186 | + if ( isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) { | |
| 187 | + $has_block = true; | |
| 188 | + break; | |
| 189 | + } | |
| 190 | + } | |
| 191 | + if ($has_block) { | |
| 192 | + break; | |
| 193 | + } | |
| 194 | + } | |
| 195 | + } | |
| 196 | + } | |
| 197 | + } | |
| 198 | + if ($has_block) { | |
| 199 | + if (!$call_common) { | |
| 200 | + $this->register_scripts_common(); | |
| 201 | + } | |
| 202 | + $css = get_option('ultp-widget', true); | |
| 203 | + if ($css) { | |
| 204 | + wp_register_style('ultp-post-widget', false ); | |
| 205 | + wp_enqueue_style('ultp-post-widget' ); | |
| 206 | + wp_add_inline_style('ultp-post-widget', $css); | |
| 207 | + } | |
| 208 | + } | |
| 73 | 209 | } |
| 74 | 210 | |
| 75 | - // Only Backend | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * Only Backend CSS and JS Scripts | |
| 214 | + * | |
| 215 | + * @since v.1.0.0 | |
| 216 | + * @return NULL | |
| 217 | + */ | |
| 76 | 218 | public function register_scripts_back_callback() { |
| 77 | 219 | $this->register_scripts_common(); |
| 78 | - wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.min.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor' ), ULTP_VER, true); | |
| 220 | + global $pagenow; | |
| 221 | + $depends = 'wp-editor'; | |
| 222 | + if ( $pagenow === 'widgets.php' ) { | |
| 223 | + $depends = 'wp-edit-widgets'; | |
| 224 | + } | |
| 225 | + wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.min.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true); | |
| 79 | 226 | wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER); |
| 80 | 227 | if(is_rtl()){ |
| 81 | 228 | wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); |
| 82 | 229 | } |
| 83 | - | |
| 84 | - $import = ''; | |
| 85 | - $options = ultimate_post()->get_setting(); | |
| 86 | - | |
| 87 | - if (isset($options['hide_import_btn'])) { | |
| 88 | - if ($options['hide_import_btn']=='yes') { | |
| 89 | - $import = 'yes'; | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 230 | + $is_active = ultimate_post()->is_lc_active(); | |
| 93 | 231 | wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array( |
| 94 | 232 | 'url' => ULTP_URL, |
| 95 | 233 | 'ajax' => admin_url('admin-ajax.php'), |
| 96 | 234 | 'security' => wp_create_nonce('ultp-nonce'), |
| 97 | - 'hide_import_btn' => $import, | |
| 235 | + 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'), | |
| 98 | 236 | 'upload' => wp_upload_dir()['basedir'] . '/ultp', |
| 99 | - 'license' => get_option('edd_ultp_license_key') | |
| 237 | + 'premium_link' => ultimate_post()->get_premium_link(), | |
| 238 | + 'license' => $is_active ? get_option('edd_ultp_license_key') : '', | |
| 239 | + 'active' => $is_active, | |
| 240 | + 'archive' => $is_active ? ultimate_post()->is_archive_builder() : '', | |
| 241 | + 'settings' => ultimate_post()->get_setting() | |
| 100 | 242 | )); |
| 243 | + | |
| 244 | + wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' ); | |
| 101 | 245 | } |
| 102 | 246 | |
| 103 | - // Fire When Plugin First Install | |
| 247 | + | |
| 248 | + /** | |
| 249 | + * Fire When Plugin First Install | |
| 250 | + * | |
| 251 | + * @since v.1.0.0 | |
| 252 | + * @return NULL | |
| 253 | + */ | |
| 104 | 254 | public function install_hook() { |
| 105 | 255 | if (!get_option('ultp_options')) { |
| 106 | 256 | ultimate_post()->init_set_data(); |
| 107 | 257 | } |
| @@ -106,8 +256,16 @@ | ||
| 106 | 256 | ultimate_post()->init_set_data(); |
| 107 | 257 | } |
| 108 | 258 | } |
| 109 | 259 | |
| 260 | + | |
| 261 | + /** | |
| 262 | + * Redirect After Active Plugin | |
| 263 | + * | |
| 264 | + * @since v.1.0.0 | |
| 265 | + * @param STRING | Plugin Path | |
| 266 | + * @return NULL | |
| 267 | + */ | |
| 110 | 268 | public function activation_redirect($plugin) { |
| 111 | 269 | if( $plugin == 'ultimate-post/ultimate-post.php' ) { |
| 112 | 270 | exit(wp_redirect(admin_url('admin.php?page=ultp-settings'))); |
| 113 | 271 | } |
| @@ -112,45 +270,103 @@ | ||
| 112 | 270 | exit(wp_redirect(admin_url('admin.php?page=ultp-settings'))); |
| 113 | 271 | } |
| 114 | 272 | } |
| 115 | 273 | |
| 116 | - // Require Blocks | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * Require Blocks | |
| 277 | + * | |
| 278 | + * @since v.1.0.0 | |
| 279 | + * @return NULL | |
| 280 | + */ | |
| 117 | 281 | public function blocks() { |
| 118 | - require_once ULTP_PATH.'blocks/Post_List_1.php'; | |
| 119 | - require_once ULTP_PATH.'blocks/Post_List_2.php'; | |
| 120 | - require_once ULTP_PATH.'blocks/Post_List_3.php'; | |
| 121 | - require_once ULTP_PATH.'blocks/Post_List_4.php'; | |
| 122 | - require_once ULTP_PATH.'blocks/Post_Slider_1.php'; | |
| 123 | - require_once ULTP_PATH.'blocks/Post_Grid_1.php'; | |
| 124 | - require_once ULTP_PATH.'blocks/Post_Grid_2.php'; | |
| 125 | - require_once ULTP_PATH.'blocks/Post_Grid_3.php'; | |
| 126 | - require_once ULTP_PATH.'blocks/Post_Grid_4.php'; | |
| 127 | - require_once ULTP_PATH.'blocks/Post_Grid_5.php'; | |
| 128 | - require_once ULTP_PATH.'blocks/Post_Grid_6.php'; | |
| 129 | - require_once ULTP_PATH.'blocks/Post_Grid_7.php'; | |
| 130 | - require_once ULTP_PATH.'blocks/Heading.php'; | |
| 131 | - require_once ULTP_PATH.'blocks/Image.php'; | |
| 132 | - require_once ULTP_PATH.'blocks/Post_Module_1.php'; | |
| 133 | - require_once ULTP_PATH.'blocks/Post_Module_2.php'; | |
| 134 | - $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1(); | |
| 135 | - $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2(); | |
| 136 | - $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3(); | |
| 137 | - $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4(); | |
| 138 | - $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1(); | |
| 139 | - $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1(); | |
| 140 | - $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2(); | |
| 141 | - $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3(); | |
| 142 | - $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4(); | |
| 143 | - $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5(); | |
| 144 | - $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6(); | |
| 145 | - $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7(); | |
| 146 | - $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading(); | |
| 147 | - $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image(); | |
| 148 | - $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1(); | |
| 149 | - $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2(); | |
| 282 | + global $unique_ID; | |
| 283 | + $setting = ultimate_post()->get_setting(); | |
| 284 | + if (!isset($setting['post_list_1']) || $setting['post_list_1'] == 'yes') { | |
| 285 | + require_once ULTP_PATH.'blocks/Post_List_1.php'; | |
| 286 | + $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1(); | |
| 287 | + } | |
| 288 | + if (!isset($setting['post_list_2']) || $setting['post_list_2'] == 'yes') { | |
| 289 | + require_once ULTP_PATH.'blocks/Post_List_2.php'; | |
| 290 | + $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2(); | |
| 291 | + } | |
| 292 | + if (!isset($setting['post_list_3']) || $setting['post_list_3'] == 'yes') { | |
| 293 | + require_once ULTP_PATH.'blocks/Post_List_3.php'; | |
| 294 | + $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3(); | |
| 295 | + } | |
| 296 | + if (!isset($setting['post_list_4']) || $setting['post_list_4'] == 'yes') { | |
| 297 | + require_once ULTP_PATH.'blocks/Post_List_4.php'; | |
| 298 | + $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4(); | |
| 299 | + } | |
| 300 | + if (!isset($setting['post_grid_1']) || $setting['post_grid_1'] == 'yes') { | |
| 301 | + require_once ULTP_PATH.'blocks/Post_Grid_1.php'; | |
| 302 | + $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1(); | |
| 303 | + } | |
| 304 | + if (!isset($setting['post_grid_2']) || $setting['post_grid_2'] == 'yes') { | |
| 305 | + require_once ULTP_PATH.'blocks/Post_Grid_2.php'; | |
| 306 | + $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2(); | |
| 307 | + } | |
| 308 | + if (!isset($setting['post_grid_3']) || $setting['post_grid_3'] == 'yes') { | |
| 309 | + require_once ULTP_PATH.'blocks/Post_Grid_3.php'; | |
| 310 | + $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3(); | |
| 311 | + } | |
| 312 | + if (!isset($setting['post_grid_4']) || $setting['post_grid_4'] == 'yes') { | |
| 313 | + require_once ULTP_PATH.'blocks/Post_Grid_4.php'; | |
| 314 | + $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4(); | |
| 315 | + } | |
| 316 | + if (!isset($setting['post_grid_5']) || $setting['post_grid_5'] == 'yes') { | |
| 317 | + require_once ULTP_PATH.'blocks/Post_Grid_5.php'; | |
| 318 | + $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5(); | |
| 319 | + } | |
| 320 | + if (!isset($setting['post_grid_6']) || $setting['post_grid_6'] == 'yes') { | |
| 321 | + require_once ULTP_PATH.'blocks/Post_Grid_6.php'; | |
| 322 | + $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6(); | |
| 323 | + } | |
| 324 | + if (!isset($setting['post_grid_7']) || $setting['post_grid_7'] == 'yes') { | |
| 325 | + require_once ULTP_PATH.'blocks/Post_Grid_7.php'; | |
| 326 | + $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7(); | |
| 327 | + } | |
| 328 | + if (!isset($setting['post_slider_1']) || $setting['post_slider_1'] == 'yes') { | |
| 329 | + require_once ULTP_PATH.'blocks/Post_Slider_1.php'; | |
| 330 | + $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1(); | |
| 331 | + } | |
| 332 | + if (!isset($setting['post_module_1']) || $setting['post_module_1'] == 'yes') { | |
| 333 | + require_once ULTP_PATH.'blocks/Post_Module_1.php'; | |
| 334 | + $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1(); | |
| 335 | + } | |
| 336 | + if (!isset($setting['post_module_2']) || $setting['post_module_2'] == 'yes') { | |
| 337 | + require_once ULTP_PATH.'blocks/Post_Module_2.php'; | |
| 338 | + $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2(); | |
| 339 | + } | |
| 340 | + if (!isset($setting['heading']) || $setting['heading'] == 'yes') { | |
| 341 | + require_once ULTP_PATH.'blocks/Heading.php'; | |
| 342 | + $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading(); | |
| 343 | + } | |
| 344 | + if (!isset($setting['image']) || $setting['image'] == 'yes') { | |
| 345 | + require_once ULTP_PATH.'blocks/Image.php'; | |
| 346 | + $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image(); | |
| 347 | + } | |
| 348 | + if (!isset($setting['taxonomy']) || $setting['taxonomy'] == 'yes') { | |
| 349 | + require_once ULTP_PATH.'blocks/Taxonomy.php'; | |
| 350 | + $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy(); | |
| 351 | + } | |
| 352 | + | |
| 353 | + if (!isset($setting['news_ticker']) || $setting['news_ticker'] == 'yes') { | |
| 354 | + require_once ULTP_PATH.'blocks/News_Ticker.php'; | |
| 355 | + $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker(); | |
| 356 | + } | |
| 357 | + | |
| 358 | + require_once ULTP_PATH.'blocks/Archive_Title.php'; | |
| 359 | + $this->all_blocks['ultimate-post_archive-title'] = new \ULTP\blocks\Archive_Title(); | |
| 150 | 360 | } |
| 151 | 361 | |
| 152 | - // Require Categories | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * Necessary Requires Class | |
| 365 | + * | |
| 366 | + * @since v.1.0.0 | |
| 367 | + * @return NULL | |
| 368 | + */ | |
| 153 | 369 | public function requires() { |
| 154 | 370 | require_once ULTP_PATH.'classes/Notice.php'; |
| 155 | 371 | require_once ULTP_PATH.'classes/Styles.php'; |
| 156 | 372 | require_once ULTP_PATH.'classes/Options.php'; |
| @@ -155,44 +371,84 @@ | ||
| 155 | 371 | require_once ULTP_PATH.'classes/Styles.php'; |
| 156 | 372 | require_once ULTP_PATH.'classes/Options.php'; |
| 157 | 373 | require_once ULTP_PATH.'classes/REST_API.php'; |
| 158 | 374 | require_once ULTP_PATH.'classes/Caches.php'; |
| 375 | + new \ULTP\REST_API(); | |
| 159 | 376 | new \ULTP\Caches(); |
| 160 | 377 | new \ULTP\Options(); |
| 161 | 378 | new \ULTP\Styles(); |
| 162 | 379 | new \ULTP\Notice(); |
| 380 | + | |
| 381 | + require_once ULTP_PATH.'classes/Deactive.php'; | |
| 382 | + new \ULTP\Deactive(); | |
| 163 | 383 | } |
| 164 | 384 | |
| 165 | - // Block Categories | |
| 385 | + | |
| 386 | + /** | |
| 387 | + * Block Categories Initialization | |
| 388 | + * | |
| 389 | + * @since v.1.0.0 | |
| 390 | + * @param $categories(ARRAY) | $post (ARRAY) | |
| 391 | + * @return NULL | |
| 392 | + */ | |
| 166 | 393 | public function register_category_callback( $categories, $post ) { |
| 167 | 394 | return array_merge( |
| 168 | 395 | array( |
| 169 | 396 | array( |
| 170 | 397 | 'slug' => 'ultimate-post', |
| 171 | - 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' ) | |
| 398 | + 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ) | |
| 172 | 399 | ) |
| 173 | 400 | ), $categories |
| 174 | 401 | ); |
| 175 | 402 | } |
| 176 | 403 | |
| 177 | - // Post View Post Meta Set | |
| 404 | + | |
| 405 | + /** | |
| 406 | + * Post View Counter for Every Post | |
| 407 | + * | |
| 408 | + * @since v.1.0.0 | |
| 409 | + * @param NUMBER | Post ID | |
| 410 | + * @return NULL | |
| 411 | + */ | |
| 178 | 412 | public function popular_posts_tracker_callback($post_id) { |
| 179 | 413 | if (!is_single()){ return; } |
| 180 | 414 | global $post; |
| 181 | - if (empty($post_id)) { $post_id = $post->ID; } | |
| 182 | - $count = (int)get_post_meta( $post_id, '__post_views_count', true ); | |
| 183 | - update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 ); | |
| 415 | + $post_id = $post->ID; | |
| 416 | + $isEnable = apply_filters('ultp_view_cookies', true); | |
| 417 | + if ($post_id && $isEnable) { | |
| 418 | + $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false; | |
| 419 | + if (!$has_cookie) { | |
| 420 | + $count = (int)get_post_meta( $post_id, '__post_views_count', true ); | |
| 421 | + update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 ); | |
| 422 | + setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies | |
| 423 | + } | |
| 424 | + } | |
| 184 | 425 | } |
| 185 | 426 | |
| 186 | - // Set Image Size | |
| 427 | + | |
| 428 | + /** | |
| 429 | + * Set Image Size | |
| 430 | + * | |
| 431 | + * @since v.1.0.0 | |
| 432 | + * @return NULL | |
| 433 | + */ | |
| 187 | 434 | public function add_image_size() { |
| 188 | - add_image_size('ultp_layout_landscape_large', 1200, 800, true); | |
| 189 | - add_image_size('ultp_layout_landscape', 870, 570, true); | |
| 190 | - add_image_size('ultp_layout_portrait', 600, 900, true); | |
| 191 | - add_image_size('ultp_layout_square', 600, 600, true); | |
| 435 | + $size_disable = ultimate_post()->get_setting('disable_image_size'); | |
| 436 | + if ($size_disable != 'yes') { | |
| 437 | + add_image_size('ultp_layout_landscape_large', 1200, 800, true); | |
| 438 | + add_image_size('ultp_layout_landscape', 870, 570, true); | |
| 439 | + add_image_size('ultp_layout_portrait', 600, 900, true); | |
| 440 | + add_image_size('ultp_layout_square', 600, 600, true); | |
| 441 | + } | |
| 192 | 442 | } |
| 193 | 443 | |
| 194 | - // Include Addons directory | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * Include Addons Directory | |
| 447 | + * | |
| 448 | + * @since v.1.0.0 | |
| 449 | + * @return NULL | |
| 450 | + */ | |
| 195 | 451 | public function include_addons() { |
| 196 | 452 | $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir'); |
| 197 | 453 | if (count($addons_dir) > 0) { |
| 198 | 454 | foreach( $addons_dir as $key => $value ) { |
| @@ -205,8 +461,14 @@ | ||
| 205 | 461 | } |
| 206 | 462 | } |
| 207 | 463 | |
| 208 | 464 | |
| 465 | + /** | |
| 466 | + * Addon Callback | |
| 467 | + * | |
| 468 | + * @since v.1.0.0 | |
| 469 | + * @return STRING | |
| 470 | + */ | |
| 209 | 471 | public function ultp_addon_callback() { |
| 210 | 472 | if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 211 | 473 | return ; |
| 212 | 474 | } |
| @@ -211,16 +473,23 @@ | ||
| 211 | 473 | return ; |
| 212 | 474 | } |
| 213 | 475 | $addon_name = sanitize_text_field($_POST['addon']); |
| 214 | 476 | $addon_value = sanitize_text_field($_POST['value']); |
| 215 | - if ($addon_name) { | |
| 477 | + if ($addon_name && current_user_can('administrator')) { | |
| 216 | 478 | $addon_data = ultimate_post()->get_setting(); |
| 217 | 479 | $addon_data[$addon_name] = $addon_value; |
| 218 | - $GLOBALS['wopb_settings'][$addon_name] = $addon_value; | |
| 480 | + $GLOBALS['ultp_settings'][$addon_name] = $addon_value; | |
| 219 | 481 | update_option('ultp_options', $addon_data); |
| 220 | 482 | } |
| 221 | 483 | } |
| 222 | 484 | |
| 485 | + | |
| 486 | + /** | |
| 487 | + * Next Preview Callback of the Blocks | |
| 488 | + * | |
| 489 | + * @since v.1.0.0 | |
| 490 | + * @return STRING | |
| 491 | + */ | |
| 223 | 492 | public function ultp_next_prev_callback() { |
| 224 | 493 | if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 225 | 494 | return ; |
| 226 | 495 | } |
| @@ -228,8 +497,10 @@ | ||
| 228 | 497 | $paged = sanitize_text_field($_POST['paged']); |
| 229 | 498 | $blockId = sanitize_text_field($_POST['blockId']); |
| 230 | 499 | $postId = sanitize_text_field($_POST['postId']); |
| 231 | 500 | $blockRaw = sanitize_text_field($_POST['blockName']); |
| 501 | + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : ''; | |
| 502 | + | |
| 232 | 503 | $blockName = str_replace('_','/', $blockRaw); |
| 233 | 504 | |
| 234 | 505 | if( $paged && $blockId && $postId && $blockName ) { |
| 235 | 506 | $post = get_post($postId); |
| @@ -234,13 +505,20 @@ | ||
| 234 | 505 | if( $paged && $blockId && $postId && $blockName ) { |
| 235 | 506 | $post = get_post($postId); |
| 236 | 507 | if (has_blocks($post->post_content)) { |
| 237 | 508 | $blocks = parse_blocks($post->post_content); |
| 238 | - $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); | |
| 509 | + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId); | |
| 239 | 510 | } |
| 240 | 511 | } |
| 241 | 512 | } |
| 242 | 513 | |
| 514 | + | |
| 515 | + /** | |
| 516 | + * Filter Callback of the Blocks | |
| 517 | + * | |
| 518 | + * @since v.1.0.0 | |
| 519 | + * @return STRING | |
| 520 | + */ | |
| 243 | 521 | public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) { |
| 244 | 522 | foreach ($blocks as $key => $value) { |
| 245 | 523 | if($blockName == $value['blockName']) { |
| 246 | 524 | if($value['attrs']['blockId'] == $blockId) { |
| @@ -245,13 +523,9 @@ | ||
| 245 | 523 | if($blockName == $value['blockName']) { |
| 246 | 524 | if($value['attrs']['blockId'] == $blockId) { |
| 247 | 525 | $attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 248 | 526 | if($taxonomy) { |
| 249 | - if($taxtype == 'category'){ | |
| 250 | - $value['attrs']['queryCat'] = json_encode(array($taxonomy)); | |
| 251 | - }elseif($taxtype == 'post_tag'){ | |
| 252 | - $value['attrs']['queryTag'] = json_encode(array($taxonomy)); | |
| 253 | - } | |
| 527 | + $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy)); | |
| 254 | 528 | $value['attrs']['queryTax'] = $taxtype; |
| 255 | 529 | } |
| 256 | 530 | if(isset($value['attrs']['queryNumber'])){ |
| 257 | 531 | $value['attrs']['queryNumber'] = $value['attrs']['queryNumber']; |
| @@ -267,8 +541,14 @@ | ||
| 267 | 541 | } |
| 268 | 542 | } |
| 269 | 543 | |
| 270 | 544 | |
| 545 | + /** | |
| 546 | + * Filter Callback of the Blocks | |
| 547 | + * | |
| 548 | + * @since v.1.0.0 | |
| 549 | + * @return STRING | |
| 550 | + */ | |
| 271 | 551 | public function ultp_filter_callback() { |
| 272 | 552 | if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 273 | 553 | return ; |
| 274 | 554 | } |
| @@ -273,15 +553,14 @@ | ||
| 273 | 553 | return ; |
| 274 | 554 | } |
| 275 | 555 | |
| 276 | 556 | $taxtype = sanitize_text_field($_POST['taxtype']); |
| 277 | - $blockId = sanitize_text_field($_POST['blockId']); | |
| 278 | - $postId = sanitize_text_field($_POST['postId']); | |
| 279 | - $taxonomy = sanitize_text_field($_POST['taxonomy']); | |
| 280 | - $blockRaw = sanitize_text_field($_POST['blockName']); | |
| 281 | - $blockName = str_replace('_','/', $blockRaw); | |
| 282 | - | |
| 283 | 557 | if( $taxtype ) { |
| 558 | + $blockId = sanitize_text_field($_POST['blockId']); | |
| 559 | + $postId = sanitize_text_field($_POST['postId']); | |
| 560 | + $taxonomy = sanitize_text_field($_POST['taxonomy']); | |
| 561 | + $blockRaw = sanitize_text_field($_POST['blockName']); | |
| 562 | + $blockName = str_replace('_','/', $blockRaw); | |
| 284 | 563 | $post = get_post($postId); |
| 285 | 564 | if (has_blocks($post->post_content)) { |
| 286 | 565 | $blocks = parse_blocks($post->post_content); |
| 287 | 566 | $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); |
| @@ -288,8 +567,15 @@ | ||
| 288 | 567 | } |
| 289 | 568 | } |
| 290 | 569 | } |
| 291 | 570 | |
| 571 | + | |
| 572 | + /** | |
| 573 | + * Pagination of the Blocks | |
| 574 | + * | |
| 575 | + * @since v.1.0.0 | |
| 576 | + * @return STRING | |
| 577 | + */ | |
| 292 | 578 | public function ultp_pagination_callback() { |
| 293 | 579 | if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) { |
| 294 | 580 | return ; |
| 295 | 581 | } |
| @@ -294,29 +580,41 @@ | ||
| 294 | 580 | return ; |
| 295 | 581 | } |
| 296 | 582 | |
| 297 | 583 | $paged = sanitize_text_field($_POST['paged']); |
| 298 | - $blockId = sanitize_text_field($_POST['blockId']); | |
| 299 | - $postId = sanitize_text_field($_POST['postId']); | |
| 300 | - $blockRaw = sanitize_text_field($_POST['blockName']); | |
| 301 | - $blockName = str_replace('_','/', $blockRaw); | |
| 302 | - | |
| 303 | 584 | if($paged) { |
| 585 | + $blockId = sanitize_text_field($_POST['blockId']); | |
| 586 | + $postId = sanitize_text_field($_POST['postId']); | |
| 587 | + $blockRaw = sanitize_text_field($_POST['blockName']); | |
| 588 | + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : ''; | |
| 589 | + $blockName = str_replace('_','/', $blockRaw); | |
| 304 | 590 | $post = get_post($postId); |
| 305 | 591 | if (has_blocks($post->post_content)) { |
| 306 | 592 | $blocks = parse_blocks($post->post_content); |
| 307 | - $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); | |
| 593 | + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId); | |
| 308 | 594 | } |
| 309 | 595 | } |
| 310 | 596 | } |
| 311 | 597 | |
| 312 | 598 | |
| 313 | - public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) { | |
| 599 | + /** | |
| 600 | + * Blocks Content Start | |
| 601 | + * | |
| 602 | + * @since v.1.0.0 | |
| 603 | + * @return STRING | |
| 604 | + */ | |
| 605 | + public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId) { | |
| 314 | 606 | foreach ($blocks as $key => $value) { |
| 315 | 607 | if($blockName == $value['blockName']) { |
| 316 | 608 | if($value['attrs']['blockId'] == $blockId) { |
| 317 | - $attr = $this->all_blocks[$blockRaw]->get_attributes(true); | |
| 318 | - $attr['paged'] = $paged; | |
| 609 | + $attr = $this->all_blocks[$blockRaw]->get_attributes(true); | |
| 610 | + $value['attrs']['paged'] = $paged; | |
| 611 | + if ($builder) { | |
| 612 | + $value['attrs']['builder'] = $builder; | |
| 613 | + } | |
| 614 | + if ($postId) { | |
| 615 | + $attr['current_post'] = $postId; | |
| 616 | + } | |
| 319 | 617 | $attr = array_merge($attr, $value['attrs']); |
| 320 | 618 | echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 321 | 619 | die(); |
| 322 | 620 | } |
| @@ -321,10 +619,10 @@ | ||
| 321 | 619 | die(); |
| 322 | 620 | } |
| 323 | 621 | } |
| 324 | 622 | if(!empty($value['innerBlocks'])){ |
| 325 | - $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName); | |
| 623 | + $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId); | |
| 326 | 624 | } |
| 327 | 625 | } |
| 328 | 626 | } |
| 329 | 627 | |
| 330 | 628 | } |