| @@ -5,14 +5,13 @@ | ||
| 5 | 5 | |
| 6 | 6 | class Initialization{ |
| 7 | 7 | |
| 8 | 8 | private $all_blocks; |
| 9 | + private $api_endpoint = 'https://demo.wpxpo.com/wp-json/restapi/v2/'; | |
| 9 | 10 | |
| 10 | 11 | public function __construct(){ |
| 11 | - $this->compatibility_check(); | |
| 12 | - $this->requires(); // Include Necessary Files | |
| 13 | - $this->blocks(); // Include Blocks | |
| 14 | - $this->include_addons(); // Include Addons | |
| 12 | + $this->requires(); | |
| 13 | + $this->blocks(); | |
| 15 | 14 | |
| 16 | 15 | add_action('wp_head', array($this, 'popular_posts_tracker_callback')); |
| 17 | 16 | add_filter('block_categories', array($this, 'register_category_callback'), 10, 2); // Block Category Register |
| 18 | 17 | add_action('after_setup_theme', array($this, 'add_image_size')); |
| @@ -19,10 +18,8 @@ | ||
| 19 | 18 | |
| 20 | 19 | add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor |
| 21 | 20 | add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel |
| 22 | 21 | add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend |
| 23 | - register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook')); | |
| 24 | - add_action( 'activated_plugin', array($this, 'activation_redirect')); | |
| 25 | 22 | |
| 26 | 23 | add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call |
| 27 | 24 | add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User |
| 28 | 25 | add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call |
| @@ -28,26 +25,21 @@ | ||
| 28 | 25 | add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call |
| 29 | 26 | add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User |
| 30 | 27 | add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call |
| 31 | 28 | 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 | |
| 33 | - } | |
| 29 | + | |
| 30 | + register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook')); | |
| 34 | 31 | |
| 35 | - public function compatibility_check(){ | |
| 36 | - require_once ULTP_PATH.'classes/Compatibility.php'; | |
| 37 | - new \ULTP\Compatibility(); | |
| 32 | + add_action( 'activated_plugin', array($this, 'activation_redirect')); | |
| 38 | 33 | } |
| 39 | 34 | |
| 40 | 35 | public function register_scripts_option_panel_callback(){ |
| 36 | + if( null !== ( $screen = get_current_screen() ) && 'toplevel_page_ultp-settings' !== $screen->id ) { | |
| 37 | + return; | |
| 38 | + } | |
| 41 | 39 | wp_enqueue_style('wp-color-picker'); |
| 42 | 40 | wp_enqueue_script('wp-color-picker'); |
| 43 | 41 | wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true); |
| 44 | - wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER); | |
| 45 | - wp_localize_script('ultp-option-script', 'ultp_option_panel', array( | |
| 46 | - 'width' => ultimate_post()->get_setting('editor_container'), | |
| 47 | - 'security' => wp_create_nonce('ultp-nonce'), | |
| 48 | - 'ajax' => admin_url('admin-ajax.php') | |
| 49 | - )); | |
| 50 | 42 | } |
| 51 | 43 | |
| 52 | 44 | public function register_scripts_common(){ |
| 53 | 45 | wp_enqueue_style('dashicons'); |
| @@ -57,9 +49,9 @@ | ||
| 57 | 49 | if(is_rtl()){ wp_enqueue_style('ultp-blocks-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); } |
| 58 | 50 | wp_enqueue_script('ultp-flexmenu-script', ULTP_URL.'assets/js/flexmenu.js', array('jquery'), ULTP_VER, true); |
| 59 | 51 | wp_enqueue_script('ultp-slick-script', ULTP_URL.'assets/js/slick.min.js', array('jquery'), ULTP_VER, true); |
| 60 | 52 | wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.js', array('jquery','ultp-flexmenu-script'), ULTP_VER, true); |
| 61 | - wp_localize_script('ultp-script', 'ultp_data_frontend', array( | |
| 53 | + wp_localize_script('ultp-script', 'ultp_data', array( | |
| 62 | 54 | 'url' => ULTP_URL, |
| 63 | 55 | 'ajax' => admin_url('admin-ajax.php'), |
| 64 | 56 | 'security' => wp_create_nonce('ultp-nonce') |
| 65 | 57 | )); |
| @@ -76,15 +68,15 @@ | ||
| 76 | 68 | public function register_scripts_back_callback() { |
| 77 | 69 | $this->register_scripts_common(); |
| 78 | 70 | 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); |
| 79 | 71 | wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER); |
| 80 | - if(is_rtl()){ | |
| 81 | - wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); | |
| 82 | - } | |
| 72 | + if(is_rtl()){ wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); } | |
| 83 | 73 | |
| 84 | 74 | $import = ''; |
| 85 | - $options = ultimate_post()->get_setting(); | |
| 86 | - | |
| 75 | + $options = get_option('ultp_options'); | |
| 76 | + if(!isset($option_data['css_save_as'])){ | |
| 77 | + $options = ultimate_post()->init_set_data(); | |
| 78 | + } | |
| 87 | 79 | if (isset($options['hide_import_btn'])) { |
| 88 | 80 | if ($options['hide_import_btn']=='yes') { |
| 89 | 81 | $import = 'yes'; |
| 90 | 82 | } |
| @@ -93,11 +85,9 @@ | ||
| 93 | 85 | wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array( |
| 94 | 86 | 'url' => ULTP_URL, |
| 95 | 87 | 'ajax' => admin_url('admin-ajax.php'), |
| 96 | 88 | 'security' => wp_create_nonce('ultp-nonce'), |
| 97 | - 'hide_import_btn' => $import, | |
| 98 | - 'upload' => wp_upload_dir()['basedir'] . '/ultp', | |
| 99 | - 'license' => get_option('edd_ultp_license_key') | |
| 89 | + 'hide_import_btn' => $import | |
| 100 | 90 | )); |
| 101 | 91 | } |
| 102 | 92 | |
| 103 | 93 | // Fire When Plugin First Install |
| @@ -112,120 +102,13 @@ | ||
| 112 | 102 | exit(wp_redirect(admin_url('admin.php?page=ultp-settings'))); |
| 113 | 103 | } |
| 114 | 104 | } |
| 115 | 105 | |
| 116 | - // Require Blocks | |
| 117 | - 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(); | |
| 150 | - } | |
| 151 | - | |
| 152 | - // Require Categories | |
| 153 | - public function requires() { | |
| 154 | - require_once ULTP_PATH.'classes/Notice.php'; | |
| 155 | - require_once ULTP_PATH.'classes/Styles.php'; | |
| 156 | - require_once ULTP_PATH.'classes/Options.php'; | |
| 157 | - require_once ULTP_PATH.'classes/REST_API.php'; | |
| 158 | - require_once ULTP_PATH.'classes/Caches.php'; | |
| 159 | - new \ULTP\Caches(); | |
| 160 | - new \ULTP\Options(); | |
| 161 | - new \ULTP\Styles(); | |
| 162 | - new \ULTP\Notice(); | |
| 163 | - } | |
| 164 | - | |
| 165 | - // Block Categories | |
| 166 | - public function register_category_callback( $categories, $post ) { | |
| 167 | - return array_merge( | |
| 168 | - array( | |
| 169 | - array( | |
| 170 | - 'slug' => 'ultimate-post', | |
| 171 | - 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' ) | |
| 172 | - ) | |
| 173 | - ), $categories | |
| 174 | - ); | |
| 175 | - } | |
| 176 | - | |
| 177 | - // Post View Post Meta Set | |
| 178 | - public function popular_posts_tracker_callback($post_id) { | |
| 179 | - if (!is_single()){ return; } | |
| 180 | - 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 ); | |
| 184 | - } | |
| 185 | - | |
| 186 | - // Set Image Size | |
| 187 | - 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); | |
| 192 | - } | |
| 193 | - | |
| 194 | - // Include Addons directory | |
| 195 | - public function include_addons() { | |
| 196 | - $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir'); | |
| 197 | - if (count($addons_dir) > 0) { | |
| 198 | - foreach( $addons_dir as $key => $value ) { | |
| 199 | - $addon_dir_name = str_replace(dirname($value).'/', '', $value); | |
| 200 | - $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php'; | |
| 201 | - if ( file_exists($file_name) ) { | |
| 202 | - include_once $file_name; | |
| 203 | - } | |
| 204 | - } | |
| 205 | - } | |
| 206 | - } | |
| 207 | - | |
| 208 | - | |
| 209 | - public function ultp_addon_callback() { | |
| 210 | - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ | |
| 106 | + public function ultp_pagination_callback() { | |
| 107 | + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) { | |
| 211 | 108 | return ; |
| 212 | 109 | } |
| 213 | - $addon_name = sanitize_text_field($_POST['addon']); | |
| 214 | - $addon_value = sanitize_text_field($_POST['value']); | |
| 215 | - if ($addon_name) { | |
| 216 | - $addon_data = ultimate_post()->get_setting(); | |
| 217 | - $addon_data[$addon_name] = $addon_value; | |
| 218 | - $GLOBALS['wopb_settings'][$addon_name] = $addon_value; | |
| 219 | - update_option('ultp_options', $addon_data); | |
| 220 | - } | |
| 221 | - } | |
| 222 | 110 | |
| 223 | - public function ultp_next_prev_callback() { | |
| 224 | - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ | |
| 225 | - return ; | |
| 226 | - } | |
| 227 | - | |
| 228 | 111 | $paged = sanitize_text_field($_POST['paged']); |
| 229 | 112 | $blockId = sanitize_text_field($_POST['blockId']); |
| 230 | 113 | $postId = sanitize_text_field($_POST['postId']); |
| 231 | 114 | $blockRaw = sanitize_text_field($_POST['blockName']); |
| @@ -230,9 +113,9 @@ | ||
| 230 | 113 | $postId = sanitize_text_field($_POST['postId']); |
| 231 | 114 | $blockRaw = sanitize_text_field($_POST['blockName']); |
| 232 | 115 | $blockName = str_replace('_','/', $blockRaw); |
| 233 | 116 | |
| 234 | - if( $paged && $blockId && $postId && $blockName ) { | |
| 117 | + if($paged) { | |
| 235 | 118 | $post = get_post($postId); |
| 236 | 119 | if (has_blocks($post->post_content)) { |
| 237 | 120 | $blocks = parse_blocks($post->post_content); |
| 238 | 121 | $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); |
| @@ -239,24 +122,14 @@ | ||
| 239 | 122 | } |
| 240 | 123 | } |
| 241 | 124 | } |
| 242 | 125 | |
| 243 | - public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) { | |
| 126 | + public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) { | |
| 244 | 127 | foreach ($blocks as $key => $value) { |
| 245 | 128 | if($blockName == $value['blockName']) { |
| 246 | 129 | if($value['attrs']['blockId'] == $blockId) { |
| 247 | 130 | $attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 248 | - 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 | - } | |
| 254 | - $value['attrs']['queryTax'] = $taxtype; | |
| 255 | - } | |
| 256 | - if(isset($value['attrs']['queryNumber'])){ | |
| 257 | - $value['attrs']['queryNumber'] = $value['attrs']['queryNumber']; | |
| 258 | - } | |
| 131 | + $attr['paged'] = $paged; | |
| 259 | 132 | $attr = array_merge($attr, $value['attrs']); |
| 260 | 133 | echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 261 | 134 | die(); |
| 262 | 135 | } |
| @@ -261,9 +134,9 @@ | ||
| 261 | 134 | die(); |
| 262 | 135 | } |
| 263 | 136 | } |
| 264 | 137 | if(!empty($value['innerBlocks'])){ |
| 265 | - $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); | |
| 138 | + $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName); | |
| 266 | 139 | } |
| 267 | 140 | } |
| 268 | 141 | } |
| 269 | 142 | |
| @@ -288,10 +161,37 @@ | ||
| 288 | 161 | } |
| 289 | 162 | } |
| 290 | 163 | } |
| 291 | 164 | |
| 292 | - public function ultp_pagination_callback() { | |
| 293 | - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) { | |
| 165 | + public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) { | |
| 166 | + foreach ($blocks as $key => $value) { | |
| 167 | + if($blockName == $value['blockName']) { | |
| 168 | + if($value['attrs']['blockId'] == $blockId) { | |
| 169 | + $attr = $this->all_blocks[$blockRaw]->get_attributes(true); | |
| 170 | + $value['attrs']['queryTax'] = $taxtype == 'category' ? 'category' : 'tag'; | |
| 171 | + if($taxtype == 'category' && $taxonomy) { | |
| 172 | + $value['attrs']['queryCat'] = json_encode(array($taxonomy)); | |
| 173 | + } | |
| 174 | + if($taxtype == 'post_tag' && $taxonomy) { | |
| 175 | + $value['attrs']['queryTag'] = json_encode(array($taxonomy)); | |
| 176 | + } | |
| 177 | + if(isset($value['attrs']['queryNumber'])){ | |
| 178 | + $value['attrs']['queryNumber'] = $value['attrs']['queryNumber']; | |
| 179 | + } | |
| 180 | + $attr = array_merge($attr, $value['attrs']); | |
| 181 | + echo $this->all_blocks[$blockRaw]->content($attr, true); | |
| 182 | + die(); | |
| 183 | + } | |
| 184 | + } | |
| 185 | + if(!empty($value['innerBlocks'])){ | |
| 186 | + $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + | |
| 192 | + public function ultp_next_prev_callback() { | |
| 193 | + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ | |
| 294 | 194 | return ; |
| 295 | 195 | } |
| 296 | 196 | |
| 297 | 197 | $paged = sanitize_text_field($_POST['paged']); |
| @@ -299,9 +199,9 @@ | ||
| 299 | 199 | $postId = sanitize_text_field($_POST['postId']); |
| 300 | 200 | $blockRaw = sanitize_text_field($_POST['blockName']); |
| 301 | 201 | $blockName = str_replace('_','/', $blockRaw); |
| 302 | 202 | |
| 303 | - if($paged) { | |
| 203 | + if( $paged && $blockId && $postId && $blockName ) { | |
| 304 | 204 | $post = get_post($postId); |
| 305 | 205 | if (has_blocks($post->post_content)) { |
| 306 | 206 | $blocks = parse_blocks($post->post_content); |
| 307 | 207 | $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); |
| @@ -308,23 +208,67 @@ | ||
| 308 | 208 | } |
| 309 | 209 | } |
| 310 | 210 | } |
| 311 | 211 | |
| 212 | + // Require Blocks | |
| 213 | + public function blocks() { | |
| 214 | + require_once ULTP_PATH.'blocks/Post_List_1.php'; | |
| 215 | + require_once ULTP_PATH.'blocks/Post_List_2.php'; | |
| 216 | + require_once ULTP_PATH.'blocks/Post_List_3.php'; | |
| 217 | + require_once ULTP_PATH.'blocks/Post_Slider_1.php'; | |
| 218 | + require_once ULTP_PATH.'blocks/Post_Grid_1.php'; | |
| 219 | + require_once ULTP_PATH.'blocks/Post_Grid_2.php'; | |
| 220 | + require_once ULTP_PATH.'blocks/Post_Grid_3.php'; | |
| 221 | + require_once ULTP_PATH.'blocks/Post_Grid_4.php'; | |
| 222 | + require_once ULTP_PATH.'blocks/Heading.php'; | |
| 223 | + require_once ULTP_PATH.'blocks/Image.php'; | |
| 224 | + //require_once ULTP_PATH.'blocks/Taxonomy.php'; | |
| 225 | + $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1(); | |
| 226 | + $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2(); | |
| 227 | + $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3(); | |
| 228 | + $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1(); | |
| 229 | + $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1(); | |
| 230 | + $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2(); | |
| 231 | + $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3(); | |
| 232 | + $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4(); | |
| 233 | + $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading(); | |
| 234 | + //$this->all_blocks['ultimate-post_taxonomy'] = new \ULTP\blocks\Taxonomy(); | |
| 235 | + $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image(); | |
| 236 | + } | |
| 312 | 237 | |
| 313 | - public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) { | |
| 314 | - foreach ($blocks as $key => $value) { | |
| 315 | - if($blockName == $value['blockName']) { | |
| 316 | - if($value['attrs']['blockId'] == $blockId) { | |
| 317 | - $attr = $this->all_blocks[$blockRaw]->get_attributes(true); | |
| 318 | - $attr['paged'] = $paged; | |
| 319 | - $attr = array_merge($attr, $value['attrs']); | |
| 320 | - echo $this->all_blocks[$blockRaw]->content($attr, true); | |
| 321 | - die(); | |
| 322 | - } | |
| 323 | - } | |
| 324 | - if(!empty($value['innerBlocks'])){ | |
| 325 | - $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName); | |
| 326 | - } | |
| 327 | - } | |
| 238 | + // Require Categories | |
| 239 | + public function requires() { | |
| 240 | + require_once ULTP_PATH.'classes/Styles.php'; | |
| 241 | + require_once ULTP_PATH.'classes/Options.php'; | |
| 242 | + require_once ULTP_PATH.'classes/REST_API.php'; | |
| 243 | + | |
| 244 | + new \ULTP\Options(); | |
| 245 | + new \ULTP\Styles(); | |
| 328 | 246 | } |
| 329 | 247 | |
| 248 | + // Block Categories | |
| 249 | + public function register_category_callback( $categories, $post ) { | |
| 250 | + return array_merge( | |
| 251 | + array( | |
| 252 | + array( | |
| 253 | + 'slug' => 'ultimate-post', | |
| 254 | + 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' ) | |
| 255 | + ) | |
| 256 | + ), $categories | |
| 257 | + ); | |
| 258 | + } | |
| 259 | + | |
| 260 | + public function popular_posts_tracker_callback($post_id) { | |
| 261 | + if (!is_single()){ return; } | |
| 262 | + global $post; | |
| 263 | + if (empty($post_id)) { $post_id = $post->ID; } | |
| 264 | + $count = (int)get_post_meta( $post_id, '__post_views_count', true ); | |
| 265 | + update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 ); | |
| 266 | + } | |
| 267 | + | |
| 268 | + public function add_image_size() { | |
| 269 | + add_image_size('ultp_layout_landscape_large', 1200, 800, true); | |
| 270 | + add_image_size('ultp_layout_landscape', 870, 570, true); | |
| 271 | + add_image_size('ultp_layout_portrait', 600, 900, true); | |
| 272 | + add_image_size('ultp_layout_square', 600, 600, true); | |
| 273 | + } | |
| 330 | 274 | } |