| 1 |
<?php |
| 2 |
/** |
| 3 |
* SURLs - Hook. |
| 4 |
* |
| 5 |
* @package Pages |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace LassoLite\Pages; |
| 9 |
|
| 10 |
use LassoLite\Admin\Constant; |
| 11 |
use LassoLite\Classes\Amazon_Api; |
| 12 |
use LassoLite\Classes\Enum; |
| 13 |
use LassoLite\Classes\Helper; |
| 14 |
use LassoLite\Classes\Page; |
| 15 |
use LassoLite\Classes\Setting; |
| 16 |
use LassoLite\Classes\Shortcode; |
| 17 |
|
| 18 |
/** |
| 19 |
* Hook. |
| 20 |
*/ |
| 21 |
class Hook { |
| 22 |
/** |
| 23 |
* Current template |
| 24 |
* |
| 25 |
* @var string $current_template |
| 26 |
*/ |
| 27 |
public $current_template = ''; |
| 28 |
|
| 29 |
/** |
| 30 |
* Is show old menus |
| 31 |
* |
| 32 |
* @var bool $show_old_menus |
| 33 |
*/ |
| 34 |
private $show_old_menus = false; |
| 35 |
|
| 36 |
/** |
| 37 |
* Register hooks |
| 38 |
*/ |
| 39 |
public function register_hooks() { |
| 40 |
add_action( 'admin_init', array( $this, 'amazon_api_pre_populated_automatically' ) ); |
| 41 |
add_action( 'init', array( $this, 'register_taxonomy' ) ); |
| 42 |
add_action( 'admin_menu', array( $this, 'build_admin_menu' ), 2 ); |
| 43 |
|
| 44 |
$lasso_shortcode = new Shortcode(); |
| 45 |
add_shortcode( 'lasso', array( $lasso_shortcode, 'lasso_lite_core_shortcode' ) ); |
| 46 |
add_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_lasso_lite' ), 10, 4 ); |
| 47 |
|
| 48 |
add_action( 'wp_head', array( $this, 'lasso_custom_css' ) ); // ? frontend |
| 49 |
add_action( 'admin_head', array( $this, 'lasso_custom_css' ) ); // ? admin |
| 50 |
add_action( 'admin_head', array( $this, 'lasso_custom_menu' ) ); // ? admin |
| 51 |
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts_frontend' ) ); // ? frontend |
| 52 |
|
| 53 |
add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) ); |
| 54 |
add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) ); |
| 55 |
|
| 56 |
// ? re-order submenu pages |
| 57 |
add_filter( 'custom_menu_order', array( $this, 'lasso_order_submenu' ) ); |
| 58 |
|
| 59 |
// ? lasso gutenberg block |
| 60 |
add_action( 'enqueue_block_editor_assets', array( $this, 'lasso_lite_gutenberg_block' ) ); |
| 61 |
|
| 62 |
// ? add Lasso button into TinyMCE |
| 63 |
add_filter( 'mce_external_plugins', array( $this, 'lasso_add_tinymce_plugin' ) ); |
| 64 |
add_filter( 'mce_buttons', array( $this, 'lasso_lite_register_my_tc_button' ) ); |
| 65 |
|
| 66 |
add_filter( 'simple_urls_redirect_url', array( $this, 'lasso_lite_redirect' ), 10, 1 ); |
| 67 |
|
| 68 |
add_action( 'admin_footer', array( $this, 'lasso_lite_admin_footer_editor_gutenberg' ) ); |
| 69 |
|
| 70 |
$setting = new Setting(); |
| 71 |
if ( $setting->is_surls_page() ) { |
| 72 |
// ? plugin: Pretty Links Pro |
| 73 |
if ( class_exists( 'PrliUpdateController' ) ) { |
| 74 |
Helper::remove_action( 'admin_notices', array( 'PrliUpdateController', 'activation_warning' ) ); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// ? FIX: CONFLICT WITH OTHER PLUGINS |
| 79 |
// ? remove js files from other plugins in Lasso pages |
| 80 |
if ( $setting->is_surls_page() ) { |
| 81 |
// ? plugin: SEO Booster |
| 82 |
if ( class_exists( 'Seobooster2' ) ) { |
| 83 |
remove_action( 'admin_print_footer_scripts', array( 'Seobooster2', 'admin_print_footer_scripts' ) ); |
| 84 |
} |
| 85 |
|
| 86 |
// ? plugin: ShortPixel Adaptive Images |
| 87 |
if ( class_exists( 'ShortPixel\AI\Notice' ) && class_exists( 'ShortPixelAI' ) ) { |
| 88 |
$spai = \ShortPixelAI::_(); |
| 89 |
$spain = \ShortPixel\AI\Notice::_( $spai ); |
| 90 |
remove_action( 'admin_footer', array( $spain, 'enqueueAdminScripts' ) ); |
| 91 |
remove_action( 'admin_bar_menu', array( $spai, 'toolbar_styles' ), 999 ); |
| 92 |
} |
| 93 |
|
| 94 |
// ? plugin: WZone - WooCommerce Amazon Affiliates (WooZone) |
| 95 |
if ( class_exists( 'WooZone' ) ) { |
| 96 |
global $WooZone; // phpcs:ignore |
| 97 |
remove_action( 'init', array( $WooZone, 'initThePlugin' ), 5 ); // phpcs:ignore |
| 98 |
} |
| 99 |
|
| 100 |
// ? plugin: Client Portal |
| 101 |
$lasso_page = $_GET['page'] ?? ''; // phpcs:ignore |
| 102 |
if ( class_exists( 'CCGClientPortal' ) && Helper::add_prefix_page( Enum::PAGE_DASHBOARD ) === $lasso_page ) { |
| 103 |
global $zohopwp; // phpcs:ignore |
| 104 |
remove_action( 'admin_menu', array( $zohopwp, 'ccgclientportal_admin_menu' ) ); // phpcs:ignore |
| 105 |
} |
| 106 |
|
| 107 |
if ( class_exists( 'wpe_admin_pointers' ) ) { |
| 108 |
global $wpe_admin_pointers; // phpcs:ignore |
| 109 |
remove_action( 'admin_enqueue_scripts', array( $wpe_admin_pointers, 'custom_admin_pointers_header' ) ); // phpcs:ignore |
| 110 |
} |
| 111 |
|
| 112 |
// ? plugin: tagDiv Composer |
| 113 |
if ( function_exists( 'td_change_backbone_js_hook' ) ) { |
| 114 |
remove_action( 'print_media_templates', 'td_change_backbone_js_hook' ); |
| 115 |
} |
| 116 |
|
| 117 |
// ? plugin: Pretty Links Pro |
| 118 |
if ( class_exists( 'PrliUpdateController' ) ) { |
| 119 |
Helper::remove_action( 'admin_notices', array( 'PrliUpdateController', 'activation_warning' ) ); |
| 120 |
} |
| 121 |
|
| 122 |
if ( Helper::is_earnist_plugin_loaded() ) { |
| 123 |
Helper::remove_action( 'admin_print_footer_scripts', array( 'EarnistProductPicker', 'register_tinymce_quicktags' ) ); |
| 124 |
} |
| 125 |
if ( Helper::is_shortcode_start_rating_plugin_loaded() ) { |
| 126 |
global $ShortcodeStarRating; // phpcs:ignore |
| 127 |
remove_action( 'admin_print_footer_scripts', array( $ShortcodeStarRating, 'appthemes_add_quicktags' ) ); // phpcs:ignore |
| 128 |
} |
| 129 |
if ( Helper::is_plugin_easy_table_of_contents_activated() ) { |
| 130 |
add_action( 'admin_enqueue_scripts', array( $this, 'remove_easy_table_of_content_action_admin_print_footer_scripts' ), 20 ); // ? admin |
| 131 |
} |
| 132 |
|
| 133 |
remove_all_actions( 'admin_footer' ); |
| 134 |
add_action( 'admin_footer', array( $this, 'lasso_print_media_templates' ) ); |
| 135 |
add_action( 'admin_footer', array( $this, 'lasso_organize_menu' ), 100 ); |
| 136 |
} |
| 137 |
|
| 138 |
// ? fix conflict with plugin Affiliate URL Automation |
| 139 |
if ( class_exists( 'AffiliateURLs' ) ) { |
| 140 |
global $AffiliateURLs; // phpcs:ignore |
| 141 |
remove_filter( 'the_content', array( &$AffiliateURLs, 'the_content' ), 12 ); // phpcs:ignore |
| 142 |
} |
| 143 |
|
| 144 |
// ? remove js files from other plugins in WP post/page pages |
| 145 |
if ( Helper::is_wordpress_post() ) { |
| 146 |
if ( class_exists( 'WooZone' ) ) { |
| 147 |
global $WooZone; // phpcs:ignore |
| 148 |
remove_action( 'init', array( $WooZone, 'initThePlugin' ), 5 ); // phpcs:ignore |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
if ( Helper::is_gravity_perks_plugin_active() ) { |
| 153 |
remove_action( 'admin_print_footer_scripts', array( 'GWPerks', 'welcome_pointer_script' ), 10 ); // phpcs:ignore |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
/** |
| 159 |
* Check if Lasso Lite shortcode then render, else return false to running the next shortcode processes |
| 160 |
* |
| 161 |
* @param boolean $false This is the default value that will be returned if the shortcode is not found. |
| 162 |
* @param string $tag The shortcode tag. |
| 163 |
* @param array $attr The attributes passed to the shortcode like so: [shortcode attr1="value" /]. |
| 164 |
* @param array $m The regex for the shortcode. |
| 165 |
* |
| 166 |
* @return string|boolean return value is the output of the lasso_lite_core_shortcode function. |
| 167 |
*/ |
| 168 |
public function filter_pre_do_shortcode_lasso_lite( $false, $tag, $attr, $m ) { |
| 169 |
if ( 'lasso' === $tag ) { |
| 170 |
return ( new Shortcode() )->lasso_lite_core_shortcode( $attr ); |
| 171 |
} |
| 172 |
|
| 173 |
return false; |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Admin menu |
| 178 |
*/ |
| 179 |
public function build_admin_menu() { |
| 180 |
$get_page = Helper::GET()['page'] ?? ''; |
| 181 |
$post_type = Helper::GET()['post_type'] ?? ''; |
| 182 |
|
| 183 |
$dashboard_slug = Helper::add_prefix_page( Enum::PAGE_DASHBOARD ); |
| 184 |
// ? Switch to new/old UI: We should easy redirect to the suitable dashboard. |
| 185 |
if ( 'switch-new-ui' === $get_page ) { |
| 186 |
update_option( Enum::SWITCH_TO_NEW_UI, 1 ); |
| 187 |
wp_redirect( Page::get_page_url( $dashboard_slug ) ); // phpcs:ignore |
| 188 |
exit; |
| 189 |
} elseif ( 'switch-old-ui' === $get_page ) { |
| 190 |
update_option( Enum::SWITCH_TO_NEW_UI, 0 ); |
| 191 |
wp_redirect( Page::get_page_url() ); // phpcs:ignore |
| 192 |
exit; |
| 193 |
} |
| 194 |
|
| 195 |
// ? Reset onboarding for testing |
| 196 |
$reset_onboarding = Helper::GET()[ Enum::RESET_WELCOME_PAGE ] ?? ''; |
| 197 |
if ( $reset_onboarding ) { |
| 198 |
Helper::update_option( Enum::IS_VISITED_WELCOME_PAGE, 0 ); |
| 199 |
update_option( Enum::LASSO_LITE_ACTIVE, 1 ); |
| 200 |
} |
| 201 |
|
| 202 |
// ? The new Lasso Lite active should be redirect to welcome page |
| 203 |
$onboarding_page = Helper::add_prefix_page( Enum::PAGE_ONBOARDING ); |
| 204 |
$should_redirect_to_welcome_page = get_option( Enum::LASSO_LITE_ACTIVE ) && ! Helper::get_option( Enum::IS_VISITED_WELCOME_PAGE ); |
| 205 |
if ( SIMPLE_URLS_SLUG === $post_type && $onboarding_page !== $get_page && $should_redirect_to_welcome_page ) { |
| 206 |
wp_redirect( Page::get_page_url( $onboarding_page ) ); // phpcs:ignore |
| 207 |
exit; |
| 208 |
} elseif ( $onboarding_page === $get_page && ! $should_redirect_to_welcome_page ) { |
| 209 |
wp_redirect( Page::get_page_url( $dashboard_slug ) ); // phpcs:ignore |
| 210 |
exit; |
| 211 |
} |
| 212 |
|
| 213 |
// ? Redirect to dashboard page if page is "surl-dashboard" and missing "post_type" parameter |
| 214 |
if ( $dashboard_slug === $get_page && ! $post_type ) { |
| 215 |
wp_redirect( Page::get_page_url( $dashboard_slug ) ); // phpcs:ignore |
| 216 |
exit; |
| 217 |
} |
| 218 |
|
| 219 |
// ? If the customer install from new UI, we should only show the new UI's menus without switch UI feature |
| 220 |
if ( get_option( Enum::LASSO_LITE_ACTIVE ) ) { |
| 221 |
update_option( Enum::SWITCH_TO_NEW_UI, 1 ); |
| 222 |
$this->apply_new_ui_menus(); |
| 223 |
} else { // ? The old client that upgrade to the new UI |
| 224 |
$switch_ui = 'switch-old-ui'; |
| 225 |
$page_title = 'Switch to old UI'; |
| 226 |
|
| 227 |
// ? The client was switched to new UI by click "Switch To New UI" |
| 228 |
if ( get_option( Enum::SWITCH_TO_NEW_UI ) ) { |
| 229 |
$this->apply_new_ui_menus(); |
| 230 |
} else { // ? The client was still using the old UI |
| 231 |
$this->show_old_menus = true; |
| 232 |
$switch_ui = 'switch-new-ui'; |
| 233 |
$page_title = 'Switch to new UI'; |
| 234 |
} |
| 235 |
|
| 236 |
add_submenu_page( |
| 237 |
'edit.php?post_type=' . SIMPLE_URLS_SLUG, |
| 238 |
$page_title, |
| 239 |
$page_title, |
| 240 |
'manage_options', |
| 241 |
Page::get_page_url( $switch_ui ) |
| 242 |
); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Apply new UI's menus |
| 248 |
*/ |
| 249 |
private function apply_new_ui_menus() { |
| 250 |
$get_page = Helper::GET()['page'] ?? ''; |
| 251 |
$post_type = Helper::GET()['post_type'] ?? ''; |
| 252 |
|
| 253 |
// ? Redirect to new UI's Dashboard if new UI enabled and the link is old UI |
| 254 |
if ( SIMPLE_URLS_SLUG === $post_type && ! $get_page ) { |
| 255 |
wp_redirect( Page::get_lite_page_url( Enum::PAGE_DASHBOARD ) ); // phpcs:ignore |
| 256 |
exit; |
| 257 |
} |
| 258 |
|
| 259 |
$new_ui_pages = Helper::available_pages(); |
| 260 |
$parent_slug = 'edit.php?post_type=' . SIMPLE_URLS_SLUG; |
| 261 |
foreach ( $new_ui_pages as $page ) { |
| 262 |
if ( $get_page === $page->slug ) { |
| 263 |
$this->current_template = $page->template; |
| 264 |
} |
| 265 |
|
| 266 |
add_submenu_page( |
| 267 |
$parent_slug, |
| 268 |
$page->title, |
| 269 |
$page->title, |
| 270 |
'manage_options', |
| 271 |
$page->slug, |
| 272 |
array( $this, 'render_html' ) |
| 273 |
); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
/** |
| 279 |
* Render html for pages |
| 280 |
*/ |
| 281 |
public function render_html() { |
| 282 |
Helper::include_with_variables( Helper::get_path_views_folder() . $this->current_template, array(), false ); |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Load css files |
| 287 |
*/ |
| 288 |
public function add_styles() { |
| 289 |
if ( ! get_option( Enum::SWITCH_TO_NEW_UI ) ) { |
| 290 |
return; |
| 291 |
} |
| 292 |
|
| 293 |
$setting = new Setting(); |
| 294 |
// @codingStandardsIgnoreStart |
| 295 |
|
| 296 |
// ? Everywhere in the Lasso Lite post-type (add/edit/reports/settings/wizard) |
| 297 |
if ( $setting->is_surls_page() ) { |
| 298 |
Helper::enqueue_style( 'bootstrap-css', 'bootstrap.min.css' ); |
| 299 |
Helper::enqueue_style( 'bootstrap-select-css', 'bootstrap-select.min.css' ); |
| 300 |
Helper::enqueue_style( 'simple-panigation-css', 'simplePagination.css' ); |
| 301 |
Helper::enqueue_style( 'select2-css', 'select2.min.css' ); |
| 302 |
Helper::enqueue_style( 'lasso-quill', 'quill.snow.css' ); |
| 303 |
Helper::enqueue_style( 'lasso-live', 'lasso-live.css', array(), 'all', false ); |
| 304 |
Helper::enqueue_style( 'lasso-display-modal', 'lasso-display-modal.css' ); |
| 305 |
Helper::enqueue_style( 'lasso-dashboard', 'lasso-dashboard.css' ); |
| 306 |
Helper::enqueue_style( 'lasso-lite-custom', 'lite-custom.css' ); |
| 307 |
} |
| 308 |
|
| 309 |
if ( $setting->is_setting_display_page() || $setting->is_setting_onboarding_page() ) { |
| 310 |
Helper::enqueue_style( 'spectrum', 'spectrum.min.css' ); |
| 311 |
} |
| 312 |
|
| 313 |
// ? LOAD LASSO DISPLAY MODAL CSS ON POST AND PAGE EDIT ONLY |
| 314 |
if ( $setting->is_wordpress_post() || $setting->is_custom_post() ) { |
| 315 |
Helper::enqueue_style( 'bootstrap-grid-css', 'bootstrap-grid.min.css' ); |
| 316 |
Helper::enqueue_style( 'lasso-display-modal', 'lasso-display-modal.css' ); |
| 317 |
Helper::enqueue_style( 'simple-pagination', 'simplePagination.css' ); |
| 318 |
Helper::enqueue_style( 'lasso-quill', 'quill.snow.css' ); |
| 319 |
Helper::enqueue_style( 'lasso-live', 'lasso-live.css', array(), 'all', false ); |
| 320 |
} |
| 321 |
|
| 322 |
// @codingStandardsIgnoreEnd |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Load js files |
| 327 |
*/ |
| 328 |
public function add_scripts() { |
| 329 |
if ( ! get_option( Enum::SWITCH_TO_NEW_UI ) ) { |
| 330 |
return; |
| 331 |
} |
| 332 |
|
| 333 |
$get = Helper::GET(); // phpcs:ignore |
| 334 |
$page = $get['page'] ?? false; |
| 335 |
$setting = new Setting(); |
| 336 |
$post_type = $setting->get['post_type'] ?? false; |
| 337 |
$setting_data = Setting::get_settings(); |
| 338 |
$support_enabled = $setting_data[ Enum::SUPPORT_ENABLED ] ?? false; |
| 339 |
$support_enabled = ! $support_enabled ? 1 : 0; |
| 340 |
$data_passed_to_js = array( |
| 341 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 342 |
'site_url' => site_url(), |
| 343 |
'plugin_url' => SIMPLE_URLS_URL, |
| 344 |
'rewrite_slug_default' => Enum::REWRITE_SLUG_DEFAULT, |
| 345 |
'simple_urls_slug' => SIMPLE_URLS_SLUG, |
| 346 |
'page_url_details' => Enum::PAGE_URL_DETAILS, |
| 347 |
'setup_progress' => Helper::get_setup_progress_information(), |
| 348 |
'optionsNonce' => wp_create_nonce( 'lasso_settings_save' ), |
| 349 |
'should_open_support_modal' => $support_enabled, |
| 350 |
'amazon_tracking_id_regex' => Amazon_Api::TRACKING_ID_REGEX, |
| 351 |
'is_onboard_page' => $setting->is_setting_onboarding_page(), |
| 352 |
); |
| 353 |
|
| 354 |
if ( SIMPLE_URLS_SLUG === $post_type ) { |
| 355 |
wp_dequeue_script( 'up_admin_script' ); // ? fix js conflict with plugin: Download plugin |
| 356 |
} |
| 357 |
|
| 358 |
// @codingStandardsIgnoreStart |
| 359 |
if ( $setting->is_wordpress_post() || $setting->is_surls_page() || $setting->is_custom_post() ) { |
| 360 |
wp_enqueue_script( 'jquery-migrate' ); // ? fix jQuery(...).live is not a function |
| 361 |
wp_enqueue_script( 'jquery' ); |
| 362 |
wp_enqueue_script( 'jquery-effects-core' ); |
| 363 |
wp_enqueue_script( 'jquery-ui-core' ); |
| 364 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 365 |
wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 366 |
|
| 367 |
Helper::enqueue_script( 'lasso-icons', 'fontawesome.min.js', array( 'jquery' ) ); |
| 368 |
Helper::enqueue_script( 'lasso-icons-regular', 'regular.min.js', array( 'jquery' ) ); |
| 369 |
Helper::enqueue_script( 'lasso-icons-solid', 'solid.min.js', array( 'jquery' ) ); |
| 370 |
Helper::enqueue_script( 'lasso-icons-brands', 'brands.min.js', array( 'jquery' ) ); |
| 371 |
Helper::enqueue_script( 'circle-progress', 'circle-progress.min.js', array( 'jquery' ) ); |
| 372 |
|
| 373 |
Helper::enqueue_script( 'lasso-quill', 'quill.min.js' ); |
| 374 |
wp_enqueue_media(); |
| 375 |
Helper::enqueue_script( 'moment-js', 'moment.min.js', array( 'jquery' ) ); |
| 376 |
Helper::enqueue_script( 'select2-js', 'select2.full.min.js', array( 'jquery' ) ); |
| 377 |
Helper::enqueue_script( SIMPLE_URLS_SLUG . '-jq-auto-complete-js', 'jquery-autocomplete.js' ); |
| 378 |
|
| 379 |
Helper::enqueue_script( 'popper-js', 'popper.min.js', array( 'jquery' ) ); |
| 380 |
Helper::enqueue_script( 'bootstrap-js', 'bootstrap.min.js', array( 'jquery' ) ); |
| 381 |
Helper::enqueue_script( 'bootstrap-select-js', 'bootstrap-select.min.js', array( 'jquery' ) ); |
| 382 |
Helper::enqueue_script( 'pagination-js', 'jquery.simplePagination.js', array( 'jquery' ) ); |
| 383 |
Helper::enqueue_script( 'jsrender', 'jsrender.min.js' ); |
| 384 |
|
| 385 |
wp_localize_script( 'jquery', 'lassoLiteOptionsData', $data_passed_to_js ); |
| 386 |
Helper::enqueue_script( 'lasso-helper', 'lasso-helper.js', array( 'jquery' ) ); |
| 387 |
Helper::enqueue_script( 'url-add', 'url-add.js', array( 'jquery' ) ); |
| 388 |
Helper::enqueue_script( 'support', 'support.js', array( 'jquery' ) ); |
| 389 |
|
| 390 |
if ( SIMPLE_URLS_SLUG . '-' . Enum::PAGE_URL_DETAILS === $page ) { |
| 391 |
Helper::enqueue_script( 'url-details', 'url-details.js', array( 'jquery' ) ); |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
if ( $setting->is_dashboard_page() ) { |
| 396 |
Helper::enqueue_script( 'dashboard', 'dashboard.js', array( 'jquery' ) ); |
| 397 |
} |
| 398 |
|
| 399 |
if ( $setting->is_setting_display_page() || $setting->is_setting_onboarding_page() ) { |
| 400 |
Helper::enqueue_script( 'spectrum-js', 'spectrum.min.js', array( 'jquery' ) ); |
| 401 |
Helper::enqueue_script( 'settings-display-js', 'settings-display.js', array( 'jquery' ) ); |
| 402 |
} |
| 403 |
|
| 404 |
if ( $setting->is_setting_amazon_page() || $setting->is_setting_onboarding_page() ) { |
| 405 |
Helper::enqueue_script( 'settings-amazon', 'settings-amazon.js', array( 'jquery' ) ); |
| 406 |
} |
| 407 |
|
| 408 |
if ( $setting->is_import_page() || $setting->is_setting_onboarding_page() ) { |
| 409 |
Helper::enqueue_script( 'settings-import', 'settings-import.js', array( 'jquery' ) ); |
| 410 |
} |
| 411 |
|
| 412 |
if ( $setting->is_setting_onboarding_page() ) { |
| 413 |
Helper::enqueue_script( 'onboarding-js', 'onboarding.js', array( 'jquery' ) ); |
| 414 |
Helper::enqueue_script( 'settings-js', 'settings.js', array( 'jquery' ) ); |
| 415 |
Helper::enqueue_script( 'settings-display-js', 'settings-display.js', array( 'jquery' ) ); |
| 416 |
} |
| 417 |
|
| 418 |
if ( $setting->is_setting_general_page() ) { |
| 419 |
Helper::enqueue_script( 'settings-general', 'settings-general.js', array( 'jquery' ) ); |
| 420 |
} |
| 421 |
|
| 422 |
if ( $setting->is_group_detail_page() || $setting->is_group_page() ) { |
| 423 |
Helper::enqueue_script( 'groups', 'groups.js', array( 'jquery' ) ); |
| 424 |
} |
| 425 |
|
| 426 |
// @codingStandardsIgnoreEnd |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* DISPLAYS CSS FOR FRONTEND OF SITE |
| 431 |
*/ |
| 432 |
public function add_scripts_frontend() { |
| 433 |
Helper::enqueue_style( 'lasso-live', 'lasso-live.css', array(), 'all', false ); |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
* DISPLAYS CUSTOM CSS FOR FRONTEND OF SITE |
| 438 |
*/ |
| 439 |
public function lasso_custom_css() { |
| 440 |
$settings = Setting::get_settings(); |
| 441 |
|
| 442 |
// @codingStandardsIgnoreStart |
| 443 |
echo '<style type="text/css"> |
| 444 |
:root{ |
| 445 |
--lasso-main: ' . $settings['display_color_main'] . ' !important; |
| 446 |
--lasso-title: ' . $settings['display_color_title'] . ' !important; |
| 447 |
--lasso-button: ' . $settings['display_color_button'] . ' !important; |
| 448 |
--lasso-secondary-button: ' . $settings['display_color_secondary_button'] . ' !important; |
| 449 |
--lasso-button-text: ' . $settings['display_color_button_text'] . ' !important; |
| 450 |
--lasso-background: ' . $settings['display_color_background'] . ' !important; |
| 451 |
--lasso-pros: ' . $settings['display_color_pros'] . ' !important; |
| 452 |
--lasso-cons: ' . $settings['display_color_cons'] . ' !important; |
| 453 |
} |
| 454 |
</style>'; |
| 455 |
|
| 456 |
// fix fontawesome js render svg (from other plugins) instead of using css |
| 457 |
echo ' |
| 458 |
<script type="text/javascript"> |
| 459 |
// Notice how this gets configured before we load Font Awesome |
| 460 |
window.FontAwesomeConfig = { autoReplaceSvg: false } |
| 461 |
</script> |
| 462 |
'; |
| 463 |
// @codingStandardsIgnoreEnd |
| 464 |
} |
| 465 |
|
| 466 |
/** |
| 467 |
* Order menu and submenu of Lasso |
| 468 |
* |
| 469 |
* @param boolean $custom_menu Whether custom ordering is enabled. Default false. |
| 470 |
*/ |
| 471 |
public function lasso_order_submenu( $custom_menu ) { |
| 472 |
global $submenu; |
| 473 |
|
| 474 |
$new_submenu = array(); |
| 475 |
$menu_key = 'edit.php?post_type=' . SIMPLE_URLS_SLUG; |
| 476 |
$lasso_lite_submenu = @$submenu[ $menu_key ]; // phpcs:ignore |
| 477 |
|
| 478 |
$parent_slug = 'edit.php?post_type=' . SIMPLE_URLS_SLUG; |
| 479 |
$hide_menu = array( |
| 480 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_SETTINGS_GENERAL, |
| 481 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_SETTINGS_AMAZON, |
| 482 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_URL_DETAILS, |
| 483 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_OPPORTUNITIES, |
| 484 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_TABLES, |
| 485 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_GROUPS, |
| 486 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_GROUP_DETAIL, |
| 487 |
); |
| 488 |
$surl_dashboard = array( |
| 489 |
SIMPLE_URLS_SLUG . '-' . Enum::PAGE_DASHBOARD, |
| 490 |
'post-new.php?post_type=' . SIMPLE_URLS_SLUG, |
| 491 |
); |
| 492 |
|
| 493 |
if ( ! empty( $lasso_lite_submenu ) ) { |
| 494 |
foreach ( $lasso_lite_submenu as $subpage ) { |
| 495 |
// ? Show the new menus |
| 496 |
if ( ! $this->show_old_menus && in_array( $subpage[2], $surl_dashboard, true ) ) { // ? Hide "Add new" and SURL Dashboard |
| 497 |
continue; |
| 498 |
} elseif ( ! $this->show_old_menus && $parent_slug === $subpage[2] ) { // ? Change title of root dashboard(all posts) menu |
| 499 |
$subpage[0] = 'Dashboard'; |
| 500 |
$new_submenu[] = $subpage; |
| 501 |
} elseif ( ! in_array( $subpage[2], $hide_menu, true ) ) { |
| 502 |
if ( SIMPLE_URLS_SLUG . '-' . Enum::PAGE_SETTINGS_DISPLAY === $subpage[2] ) { |
| 503 |
$subpage[0] = 'Settings'; |
| 504 |
} |
| 505 |
|
| 506 |
$new_submenu[] = $subpage; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
$new_submenu[90] = array( |
| 511 |
'Support', |
| 512 |
'manage_options', |
| 513 |
Constant::LASSO_SUPPORT_URL, |
| 514 |
); |
| 515 |
|
| 516 |
$new_submenu[100] = array( |
| 517 |
'<b class="green">Upgrade to Pro</b>', |
| 518 |
'manage_options', |
| 519 |
Constant::LASSO_UPGRADE_URL, |
| 520 |
); |
| 521 |
} |
| 522 |
|
| 523 |
// ? ERROR | Overriding WordPress globals is prohibited. Found assignment to $submenu |
| 524 |
// phpcs:ignore |
| 525 |
$submenu[ $menu_key ] = $new_submenu; |
| 526 |
} |
| 527 |
|
| 528 |
/** |
| 529 |
* Load lasso js file in Gutenberg editor |
| 530 |
*/ |
| 531 |
public function lasso_lite_gutenberg_block() { |
| 532 |
if ( ! Helper::is_lasso_pro_plugin_active() ) { |
| 533 |
Helper::enqueue_script( 'lasso-lite-gutenberg-block', 'lasso-lite-gutenberg-block.js', array( 'wp-blocks', 'wp-editor' ) ); |
| 534 |
Helper::enqueue_script( 'display-add', 'display-add.js', array( 'jquery' ) ); |
| 535 |
Helper::enqueue_script( 'url-add', 'url-add.js', array( 'jquery' ) ); |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* Load lasso js file in Classic editor (TinyMCE) |
| 541 |
* |
| 542 |
* @param array $plugin_array An array of external TinyMCE plugins. |
| 543 |
*/ |
| 544 |
public function lasso_add_tinymce_plugin( $plugin_array ) { |
| 545 |
if ( ! Helper::is_lasso_pro_plugin_active() ) { |
| 546 |
$lasso_setting = new Setting(); |
| 547 |
if ( Helper::is_classic_editor_plugin_active() && ( $lasso_setting->is_wordpress_post() || $lasso_setting->is_custom_post() ) ) { |
| 548 |
$plugin_array['lasso_lite_tc_button'] = SIMPLE_URLS_URL . '/admin/assets/js/lasso-lite-display-modal.js?v=' . strval( @filemtime( SIMPLE_URLS_DIR . '/admin/assets/js/lasso-display-modal.js' ) ); // phpcs:ignore |
| 549 |
Helper::enqueue_script( 'display-add', 'display-add.js', array( 'jquery' ) ); |
| 550 |
Helper::enqueue_script( 'url-add', 'url-add.js', array( 'jquery' ) ); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
return $plugin_array; |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Add Lasso button to Classic editor (TinyMCE) |
| 559 |
* |
| 560 |
* @param array $buttons First-row list of buttons. |
| 561 |
*/ |
| 562 |
public function lasso_lite_register_my_tc_button( $buttons ) { |
| 563 |
if ( ! Helper::is_lasso_pro_plugin_active() ) { |
| 564 |
array_push( $buttons, 'lasso_lite_tc_button' ); |
| 565 |
array_push( $buttons, 'lasso_grid_button' ); |
| 566 |
} |
| 567 |
|
| 568 |
return $buttons; |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* Render template in admin footer on screen editor Gutenberg |
| 573 |
*/ |
| 574 |
public function lasso_lite_admin_footer_editor_gutenberg() { |
| 575 |
if ( ! Helper::is_lasso_pro_plugin_active() ) { |
| 576 |
$lasso_setting = new Setting(); |
| 577 |
|
| 578 |
if ( $lasso_setting->is_wordpress_post() || $lasso_setting->is_custom_post() ) { |
| 579 |
$current_screen = get_current_screen(); |
| 580 |
// ? Check to make sure render html only block editor Gutenberg |
| 581 |
if ( ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) || ( function_exists( 'is_gutenberg_page' ) ) && is_gutenberg_page() ) { |
| 582 |
echo Helper::get_display_modal_html(); // phpcs:ignore |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* Custom target menu |
| 590 |
*/ |
| 591 |
public function lasso_custom_menu() { |
| 592 |
?> |
| 593 |
<script type="text/javascript"> |
| 594 |
jQuery( document ).ready( function( $ ) { |
| 595 |
jQuery( "ul#adminmenu a[href$='<?php echo Constant::LASSO_SUPPORT_URL; // phpcs:ignore ?>']" ).attr( 'target', '_blank' ); |
| 596 |
jQuery( "ul#adminmenu a[href$='<?php echo Constant::LASSO_UPGRADE_URL; // phpcs:ignore ?>']" ).attr( 'target', '_blank' ); |
| 597 |
} ); |
| 598 |
</script> |
| 599 |
<?php |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Add Amazon tracking id to redirect link |
| 604 |
* |
| 605 |
* @param string $redirect Redirect link. |
| 606 |
*/ |
| 607 |
public function lasso_lite_redirect( $redirect ) { |
| 608 |
if ( Amazon_Api::is_amazon_url( $redirect ) ) { |
| 609 |
$redirect = Amazon_Api::get_amazon_product_url( $redirect ); |
| 610 |
} |
| 611 |
|
| 612 |
return $redirect; |
| 613 |
} |
| 614 |
|
| 615 |
/** |
| 616 |
* Pull Amazon API information is stored in AAWP, or Amalinks Pro automatically. |
| 617 |
* |
| 618 |
* @return $this |
| 619 |
*/ |
| 620 |
public function amazon_api_pre_populated_automatically() { |
| 621 |
if ( Helper::get_option( Enum::IS_PRE_POPULATED_AMAZON_API ) ) { |
| 622 |
return $this; |
| 623 |
} |
| 624 |
|
| 625 |
$api_key = ''; |
| 626 |
$api_secret = ''; |
| 627 |
$country = ''; |
| 628 |
$tracking_id = ''; |
| 629 |
|
| 630 |
// ? AAWP plugin |
| 631 |
if ( Helper::is_aawp_active() ) { |
| 632 |
$aawp_api = get_option( 'aawp_api' ); |
| 633 |
|
| 634 |
$api_key = $aawp_api['key'] ?? ''; |
| 635 |
$api_secret = $aawp_api['secret'] ?? ''; |
| 636 |
$country = $aawp_api['country'] ?? ''; |
| 637 |
$tracking_id = $aawp_api['associate_tag'] ?? ''; |
| 638 |
} |
| 639 |
|
| 640 |
// ? AmaLinksPro plugin |
| 641 |
if ( empty( $api_key ) && empty( $api_secret ) && empty( $tracking_id ) && Helper::is_amalinks_pro_active() ) { |
| 642 |
$api_key = get_option( 'amalinkspro-options_amazon_api_access_key', '' ); |
| 643 |
$api_secret = get_option( 'amalinkspro-options_amazon_api_secret_key', '' ); |
| 644 |
$country = get_option( 'amalinkspro-options_default_amazon_search_locale', '' ); |
| 645 |
if ( ! empty( $country ) ) { |
| 646 |
$tracking_id = get_option( 'amalinkspro-options_' . $country . '_amazon_associate_ids_0_associate_id', '' ); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
$lasso_options = Setting::get_settings(); |
| 651 |
$amazon_access_key_id = $lasso_options['amazon_access_key_id'] ?? ''; |
| 652 |
$amazon_secret_key = $lasso_options['amazon_secret_key'] ?? ''; |
| 653 |
$amazon_tracking_id = $lasso_options['amazon_tracking_id'] ?? ''; |
| 654 |
|
| 655 |
if ( empty( $amazon_access_key_id ) && empty( $amazon_secret_key ) && empty( $amazon_tracking_id ) |
| 656 |
&& ! empty( $api_key ) && ! empty( $api_secret ) && ! empty( $tracking_id ) && ! empty( $country ) |
| 657 |
) { |
| 658 |
$country = strtolower( $country ); |
| 659 |
|
| 660 |
Setting::set_setting( 'amazon_access_key_id', $api_key ); |
| 661 |
Setting::set_setting( 'amazon_secret_key', $api_secret ); |
| 662 |
Setting::set_setting( 'amazon_default_tracking_country', $country ); |
| 663 |
Setting::set_setting( 'amazon_tracking_id', $tracking_id ); |
| 664 |
|
| 665 |
Helper::update_option( Enum::IS_PRE_POPULATED_AMAZON_API, 1 ); |
| 666 |
} |
| 667 |
|
| 668 |
return $this; |
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* Remove action "admin_print_footer_scripts" of "Easy Table of Contents" plugin |
| 673 |
*/ |
| 674 |
public function remove_easy_table_of_content_action_admin_print_footer_scripts() { |
| 675 |
Helper::remove_action( 'admin_print_footer_scripts', array( 'eztoc_pointers', 'admin_print_footer_scripts' ) ); |
| 676 |
} |
| 677 |
|
| 678 |
/** |
| 679 |
* Prints the templates used in the media manager. |
| 680 |
*/ |
| 681 |
public function lasso_print_media_templates() { |
| 682 |
wp_print_media_templates(); |
| 683 |
} |
| 684 |
|
| 685 |
/** |
| 686 |
* Add active class to the current page |
| 687 |
*/ |
| 688 |
public function lasso_organize_menu() { |
| 689 |
$setting_page = ( new Setting() )->is_setting_page(); |
| 690 |
?> |
| 691 |
<script> |
| 692 |
jQuery(document).ready(function(){ |
| 693 |
var lasso_menu = jQuery('#menu-posts-surl'); |
| 694 |
if(lasso_menu.is('.wp-has-current-submenu, .wp-menu-open')){ |
| 695 |
var submenu = lasso_menu.find('ul.wp-submenu').find('li'); |
| 696 |
if(submenu != undefined) { |
| 697 |
if(!submenu.hasClass('current') || submenu.hasClass('current').length == 0) { |
| 698 |
submenu.eq(1).addClass('current'); |
| 699 |
} |
| 700 |
|
| 701 |
// add class `current` for Settings menu |
| 702 |
if('<?php echo (int) $setting_page; ?>' == '1') { |
| 703 |
submenu.removeClass('current'); |
| 704 |
lasso_menu.find('ul.wp-submenu').find('li:contains("Settings")').addClass('current'); |
| 705 |
} |
| 706 |
} |
| 707 |
} |
| 708 |
}); |
| 709 |
</script> |
| 710 |
<?php |
| 711 |
} |
| 712 |
|
| 713 |
/** |
| 714 |
* Register a category |
| 715 |
*/ |
| 716 |
public function register_taxonomy() { |
| 717 |
// ? register custom taxonomy |
| 718 |
register_taxonomy( |
| 719 |
Constant::LASSO_CATEGORY, |
| 720 |
Constant::LASSO_POST_TYPE, |
| 721 |
array( |
| 722 |
'label' => __( 'Lasso Categories' ), |
| 723 |
'rewrite' => array( 'slug' => Constant::LASSO_CATEGORY ), |
| 724 |
'hierarchical' => false, |
| 725 |
'public' => false, |
| 726 |
'labels' => array( |
| 727 |
'add_new_item' => __( 'Add New Category' ), |
| 728 |
'edit_item' => __( 'Edit Categories' ), |
| 729 |
), |
| 730 |
) |
| 731 |
); |
| 732 |
} |
| 733 |
} |
| 734 |
|