classes
5 years ago
compatibility
5 years ago
metaboxes
6 years ago
modules
9 years ago
admin-ajax.php
6 years ago
admin-hooks.php
5 years ago
admin-the-functions.php
6 years ago
index.php
5 years ago
admin-hooks.php
983 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | /*-----------------------------------------------------------------------------------*/ |
| 7 | /* Add shortcode button to tinymce |
| 8 | /*-----------------------------------------------------------------------------------*/ |
| 9 | |
| 10 | function auxin_register_shortcode_button( $buttons ) { |
| 11 | array_push( $buttons, '|', 'phlox_shortcodes_button' ); |
| 12 | return $buttons; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Add the shortcode button to TinyMCE |
| 17 | * |
| 18 | * @param array $plugin_array |
| 19 | * @return array |
| 20 | */ |
| 21 | function auxin_add_elements_tinymce_plugin( $plugin_array ) { |
| 22 | $wp_version = get_bloginfo( 'version' ); |
| 23 | |
| 24 | $plugin_array['phlox_shortcodes_button'] = AUXELS_ADMIN_URL."/assets/js/tinymce/plugins/auxin-btns.js"; |
| 25 | |
| 26 | return $plugin_array; |
| 27 | } |
| 28 | |
| 29 | |
| 30 | function auxels_init_shortcode_manager(){ |
| 31 | if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) |
| 32 | return; |
| 33 | |
| 34 | add_filter( 'mce_external_plugins', 'auxin_add_elements_tinymce_plugin' ); |
| 35 | add_filter( 'mce_buttons', 'auxin_register_shortcode_button' ); |
| 36 | } |
| 37 | add_action("init", "auxels_init_shortcode_manager"); |
| 38 | |
| 39 | |
| 40 | /*-----------------------------------------------------------------------------------*/ |
| 41 | /* Wizard admin notice |
| 42 | /*-----------------------------------------------------------------------------------*/ |
| 43 | |
| 44 | /** |
| 45 | * Skip the notice for running the setup wizard |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | function auxels_hide_wizard_notice() { |
| 50 | if ( isset( $_GET['auxels-hide-wizard-notice'] ) && isset( $_GET['_notice_nonce'] ) ) { |
| 51 | if ( ! wp_verify_nonce( $_GET['_notice_nonce'], 'auxels_hide_notices_nonce' ) ) { |
| 52 | wp_die( __( 'Authorization failed. Please refresh the page and try again.', 'auxin-elements' ) ); |
| 53 | } |
| 54 | auxin_update_option( 'auxels_hide_wizard_notice', 1 ); |
| 55 | } |
| 56 | } |
| 57 | add_action( 'wp_loaded', 'auxels_hide_wizard_notice' ); |
| 58 | |
| 59 | /*-----------------------------------------------------------------------------------*/ |
| 60 | /* Add Editor styles |
| 61 | /*-----------------------------------------------------------------------------------*/ |
| 62 | |
| 63 | function auxin_register_mce_buttons_style(){ |
| 64 | wp_register_style('auxin_mce_buttons' , AUXELS_ADMIN_URL. '/assets/css/editor.css', NULL, '1.1'); |
| 65 | wp_enqueue_style('auxin_mce_buttons'); |
| 66 | } |
| 67 | add_action('admin_enqueue_scripts', 'auxin_register_mce_buttons_style'); |
| 68 | |
| 69 | /*-----------------------------------------------------------------------------------*/ |
| 70 | /* Adding a plugin to plugin recommendation list |
| 71 | /*-----------------------------------------------------------------------------------*/ |
| 72 | |
| 73 | function auxels_plugin_register_recommended_plugins() { |
| 74 | |
| 75 | if( is_rtl() ){ |
| 76 | $plugins = array( |
| 77 | array( |
| 78 | 'name' => __('Phlox RTL Fonts', 'auxin-elements'), |
| 79 | 'slug' => 'auxin-fonts', |
| 80 | 'version' => '1.0.0', |
| 81 | 'source' => AUXELS_DIR . '/embeds/plugins/auxin-fonts.zip', // The "internal" source of the plugin. |
| 82 | 'required' => false |
| 83 | ) |
| 84 | ); |
| 85 | tgmpa( $plugins ); |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | add_action( 'tgmpa_register', 'auxels_plugin_register_recommended_plugins', 12 ); |
| 91 | |
| 92 | /*-----------------------------------------------------------------------------------*/ |
| 93 | /* Adds subtitle meta field to 'Title setting' tab |
| 94 | /*-----------------------------------------------------------------------------------*/ |
| 95 | |
| 96 | function auxin_add_metabox_field_to_title_setting_tab( $fields, $id, $type ){ |
| 97 | |
| 98 | if( 'general-title' == $id ){ |
| 99 | array_splice( |
| 100 | $fields, |
| 101 | 1, 0, |
| 102 | array( |
| 103 | array( |
| 104 | 'title' => __('Subtitle for Title Bar', 'auxin-elements'), |
| 105 | 'description' => __('Second Title for title bar (optional). Note: You have to enable "Display Title Bar Section" option in order to display the subtitle.', 'auxin-elements'), |
| 106 | 'id' => 'page_subtitle', |
| 107 | 'type' => 'editor', |
| 108 | 'default' => '', |
| 109 | 'dependency' => array( |
| 110 | array( |
| 111 | 'id' => 'aux_title_bar_show', |
| 112 | 'value' => array('default', 'yes'), |
| 113 | 'operator'=> '==' |
| 114 | ) |
| 115 | ) |
| 116 | ), |
| 117 | array( |
| 118 | 'title' => __('Subtitle Position', 'auxin-elements'), |
| 119 | 'description' => '', |
| 120 | 'id' => 'subtitle_position', |
| 121 | 'type' => 'select', |
| 122 | 'default' => 'after', |
| 123 | 'choices' => array( |
| 124 | 'before' => __( 'Before Title', 'auxin-elements' ), |
| 125 | 'after' => __( 'After Title', 'auxin-elements' ), |
| 126 | ), |
| 127 | 'dependency' => array( |
| 128 | array( |
| 129 | 'id' => 'aux_title_bar_show', |
| 130 | 'value' => array('default', 'yes'), |
| 131 | 'operator'=> '==' |
| 132 | ) |
| 133 | ) |
| 134 | ) |
| 135 | ) |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | return $fields; |
| 140 | } |
| 141 | add_filter( 'auxin_metabox_fields', 'auxin_add_metabox_field_to_title_setting_tab', 10, 3 ); |
| 142 | |
| 143 | |
| 144 | /*-----------------------------------------------------------------------------------*/ |
| 145 | /* Registers special theme admin menu |
| 146 | /*-----------------------------------------------------------------------------------*/ |
| 147 | |
| 148 | function auxin_elements_admin_bar_add_upgrade_phlox( $wp_admin_bar ){ |
| 149 | |
| 150 | // Skip for Pro version |
| 151 | if( defined('THEME_PRO') && THEME_PRO ){ |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | $wp_admin_bar->add_menu( array( |
| 156 | 'id' => 'phlox-upgrade', |
| 157 | 'title' => __( 'Upgrade Phlox', 'auxin-elements' ), |
| 158 | 'parent' => 'top-secondary', |
| 159 | 'href' => esc_url( 'http://phlox.pro/go-pro/?utm_source=phlox-welcome&utm_medium=phlox-free&utm_campaign=phlox-go-pro&utm_content=adminbar' ), |
| 160 | 'meta' => array( |
| 161 | 'class' => 'auxin-upgrade-top-bar', |
| 162 | 'target' => '_blank' |
| 163 | ) |
| 164 | )); |
| 165 | |
| 166 | } |
| 167 | add_action( 'admin_bar_menu', 'auxin_elements_admin_bar_add_upgrade_phlox', 199 ); |
| 168 | |
| 169 | |
| 170 | function auxin_elements_admin_bar_notices( $wp_admin_bar ){ |
| 171 | |
| 172 | if( auxin_get_option( 'auxin_maintenance_enable', 0 ) ){ |
| 173 | $wp_admin_bar->add_menu( array( |
| 174 | 'id' => 'phlox-maintenance', |
| 175 | 'title' => __( 'Maintenance Mode', 'auxin-elements' ), |
| 176 | 'parent' => 'top-secondary', |
| 177 | 'href' => self_admin_url( 'customize.php?autofocus[control]=auxin_maintenance_enable_control' ), |
| 178 | 'meta' => array( |
| 179 | 'class' => 'auxin-alarm-top-bar', |
| 180 | 'target' => '_self' |
| 181 | ) |
| 182 | )); |
| 183 | } |
| 184 | |
| 185 | } |
| 186 | add_action( 'admin_bar_menu', 'auxin_elements_admin_bar_notices', 195 ); |
| 187 | |
| 188 | /** |
| 189 | * Remove theme submenu under appearance |
| 190 | * |
| 191 | * @return void |
| 192 | */ |
| 193 | function auxin_elements_remnove_theme_submenu(){ |
| 194 | remove_submenu_page( "themes.php", "tgmpa-install-plugins"); |
| 195 | } |
| 196 | add_action( "admin_menu", "auxin_elements_remnove_theme_submenu", 12 ); |
| 197 | |
| 198 | |
| 199 | /*-----------------------------------------------------------------------------------*/ |
| 200 | /* Check Bundled Plugins Updates |
| 201 | /*-----------------------------------------------------------------------------------*/ |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * Add a submenu to TGMPA plugins update page |
| 206 | * |
| 207 | * @return void |
| 208 | */ |
| 209 | function auxin_register_update_plugins_submenu(){ |
| 210 | global $menu; |
| 211 | |
| 212 | if( ! defined('THEME_PRO') || ! THEME_PRO ) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // Update Plugins SubMenu |
| 217 | if( $tgmpa_counter = auxin_count_bundled_plugins_have_update() ) { |
| 218 | add_submenu_page( |
| 219 | 'auxin-welcome', |
| 220 | esc_attr__( 'Update Plugins' , 'auxin-elements' ), |
| 221 | sprintf( __( 'Update Plugins %s' , 'auxin-elements' ), " <span class='update-plugins count-1'><span class='update-count'>". number_format_i18n( $tgmpa_counter ) ."</span></span>" ), |
| 222 | 'manage_options', |
| 223 | 'auxin-update', |
| 224 | 'auxin_get_tgmpa_plugins_page' |
| 225 | ); |
| 226 | } |
| 227 | } |
| 228 | add_action( 'admin_menu', 'auxin_register_update_plugins_submenu', 30 ); |
| 229 | |
| 230 | |
| 231 | /** |
| 232 | * Remove transient on plugin upgrade |
| 233 | * |
| 234 | * @return void |
| 235 | */ |
| 236 | function auxin_remove_bundled_plugins_update_transient(){ |
| 237 | delete_transient( 'auxin_count_bundled_plugins_have_update' ); |
| 238 | } |
| 239 | add_action( 'upgrader_process_complete', 'auxin_remove_bundled_plugins_update_transient' ); |
| 240 | add_action( 'auxin_updated' , 'auxin_remove_bundled_plugins_update_transient' ); |
| 241 | |
| 242 | /** |
| 243 | * Add bundled plugins update count to admin theme menu |
| 244 | * |
| 245 | * @param int $count The number if bubble count |
| 246 | * @return int $count |
| 247 | */ |
| 248 | function auxin_add_update_count_to_theme_menu( $count ){ |
| 249 | if( $total_updates = auxin_get_total_updates() ) { |
| 250 | $count = $count + $total_updates; |
| 251 | } |
| 252 | return $count; |
| 253 | } |
| 254 | add_action( 'auxin_theme_menu_update_count', 'auxin_add_update_count_to_theme_menu' ); |
| 255 | |
| 256 | /*-----------------------------------------------------------------------------------*/ |
| 257 | /* Adding fallback for deprecated theme option name |
| 258 | /*-----------------------------------------------------------------------------------*/ |
| 259 | |
| 260 | function auxels_sync_deprecated_options(){ |
| 261 | |
| 262 | $old_theme_options = get_option( THEME_ID . '_formatted_options' ); |
| 263 | if( false === $old_theme_options ){ |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | $new_theme_options = get_option( THEME_ID . '_theme_options' ); |
| 268 | if( false === $new_theme_options ){ |
| 269 | update_option( THEME_ID . '_theme_options', $old_theme_options ); |
| 270 | } |
| 271 | } |
| 272 | add_action( 'admin_init', 'auxels_sync_deprecated_options' ); |
| 273 | |
| 274 | /*-----------------------------------------------------------------------------------*/ |
| 275 | /* Add post format related metafields to post |
| 276 | /*-----------------------------------------------------------------------------------*/ |
| 277 | |
| 278 | function auxels_add_post_metabox_models( $models ){ |
| 279 | |
| 280 | // Load general metabox models |
| 281 | include_once( 'metaboxes/metabox-fields-post-audio.php' ); |
| 282 | include_once( 'metaboxes/metabox-fields-post-gallery.php' ); |
| 283 | include_once( 'metaboxes/metabox-fields-post-quote.php' ); |
| 284 | include_once( 'metaboxes/metabox-fields-post-video.php' ); |
| 285 | |
| 286 | $models[] = array( |
| 287 | 'model' => auxin_metabox_fields_post_gallery(), |
| 288 | 'priority' => 20 |
| 289 | ); |
| 290 | |
| 291 | $models[] = array( |
| 292 | 'model' => auxin_metabox_fields_post_video(), |
| 293 | 'priority' => 22 |
| 294 | ); |
| 295 | |
| 296 | $models[] = array( |
| 297 | 'model' => auxin_metabox_fields_post_audio(), |
| 298 | 'priority' => 24 |
| 299 | ); |
| 300 | |
| 301 | $models[] = array( |
| 302 | 'model' => auxin_metabox_fields_post_quote(), |
| 303 | 'priority' => 26 |
| 304 | ); |
| 305 | |
| 306 | $models[] = array( |
| 307 | 'model' => auxin_metabox_fields_general_advanced(), |
| 308 | 'priority' => 36 |
| 309 | ); |
| 310 | |
| 311 | return $models; |
| 312 | } |
| 313 | |
| 314 | add_filter( 'auxin_admin_metabox_models_post', 'auxels_add_post_metabox_models' ); |
| 315 | |
| 316 | /*-----------------------------------------------------------------------------------*/ |
| 317 | /* Add advanced metafields to page |
| 318 | /*-----------------------------------------------------------------------------------*/ |
| 319 | |
| 320 | function auxels_add_page_metabox_models( $models ){ |
| 321 | include_once( 'metaboxes/metabox-fields-general-header-template-settings.php'); |
| 322 | include_once( 'metaboxes/metabox-fields-general-header-template.php'); |
| 323 | include_once( 'metaboxes/metabox-fields-general-custom-logo.php'); |
| 324 | include_once( 'metaboxes/metabox-fields-general-top-header.php'); |
| 325 | include_once( 'metaboxes/metabox-fields-general-header.php'); |
| 326 | include_once( 'metaboxes/metabox-fields-general-footer-template-settings.php'); |
| 327 | include_once( 'metaboxes/metabox-fields-general-footer-template.php'); |
| 328 | include_once( 'metaboxes/metabox-fields-general-footer.php'); |
| 329 | include_once( 'metaboxes/metabox-fields-page-template.php'); |
| 330 | |
| 331 | $models[] = array( |
| 332 | 'model' => auxin_metabox_fields_general_custom_logo(), |
| 333 | 'priority' => 2 |
| 334 | ); |
| 335 | |
| 336 | $models[] = array( |
| 337 | 'model' => auxin_metabox_fields_header_templates(), |
| 338 | 'priority' => 3 |
| 339 | ); |
| 340 | |
| 341 | $models[] = array( |
| 342 | 'model' => auxin_metabox_fields_header_templates_settings(), |
| 343 | 'priority' => 4 |
| 344 | ); |
| 345 | |
| 346 | $models[] = array( |
| 347 | 'model' => auxin_metabox_fields_page_template(), |
| 348 | 'priority' => 8 |
| 349 | ); |
| 350 | |
| 351 | $models[] = array( |
| 352 | 'model' => auxin_metabox_fields_footer_templates(), |
| 353 | 'priority' => 9 |
| 354 | ); |
| 355 | |
| 356 | $models[] = array( |
| 357 | 'model' => auxin_metabox_fields_footer_templates_settings(), |
| 358 | 'priority' => 10 |
| 359 | ); |
| 360 | |
| 361 | $models[] = array( |
| 362 | 'model' => auxin_metabox_fields_general_advanced(), |
| 363 | 'priority' => 11 |
| 364 | ); |
| 365 | |
| 366 | $models[] = array( |
| 367 | 'model' => auxin_metabox_fields_general_header(), |
| 368 | 'priority' => 12 |
| 369 | ); |
| 370 | |
| 371 | $models[] = array( |
| 372 | 'model' => auxin_metabox_fields_general_top_header(), |
| 373 | 'priority' => 13 |
| 374 | ); |
| 375 | |
| 376 | $models[] = array( |
| 377 | 'model' => auxin_metabox_fields_general_footer(), |
| 378 | 'priority' => 14 |
| 379 | ); |
| 380 | |
| 381 | return $models; |
| 382 | } |
| 383 | |
| 384 | add_filter( 'auxin_admin_metabox_models_page', 'auxels_add_page_metabox_models' ); |
| 385 | |
| 386 | /*-----------------------------------------------------------------------------------*/ |
| 387 | /* Add theme tab in siteorigin page builder |
| 388 | /*-----------------------------------------------------------------------------------*/ |
| 389 | |
| 390 | function auxin_add_widget_tabs($tabs) { |
| 391 | $tabs[] = array( |
| 392 | 'title' => THEME_NAME, |
| 393 | 'filter' => array( |
| 394 | 'groups' => array('auxin') |
| 395 | ) |
| 396 | ); |
| 397 | |
| 398 | if (isset($tabs['recommended'])){ |
| 399 | unset($tabs['recommended']); |
| 400 | } |
| 401 | |
| 402 | |
| 403 | return $tabs; |
| 404 | } |
| 405 | add_filter( 'siteorigin_panels_widget_dialog_tabs', 'auxin_add_widget_tabs', 20 ); |
| 406 | |
| 407 | // ============================================================================= |
| 408 | |
| 409 | function auxin_admin_footer_text( $footer_text ) { |
| 410 | |
| 411 | // the admin pages that we intent to display theme footer text on |
| 412 | $admin_pages = array( |
| 413 | 'toplevel_page_auxin', |
| 414 | 'appearance_page_auxin', |
| 415 | 'toplevel_page_auxin-welcome', |
| 416 | 'appearance_page_auxin-welcome', |
| 417 | 'page', |
| 418 | 'post', |
| 419 | 'widgets', |
| 420 | 'dashboard', |
| 421 | 'edit-post', |
| 422 | 'edit-page', |
| 423 | 'edit-portfolio', |
| 424 | 'edit-faq', |
| 425 | 'edit-product' |
| 426 | ); |
| 427 | |
| 428 | if( ! ( function_exists('auxin_is_theme_admin_page') && auxin_is_theme_admin_page( $admin_pages ) ) ){ |
| 429 | return $footer_text; |
| 430 | } |
| 431 | |
| 432 | $welcome_tab_url = self_admin_url( 'admin.php?page=auxin-welcome&tab=' ); |
| 433 | $setup_wizard_url = self_admin_url( 'admin.php?page=auxin-wizard' ); |
| 434 | |
| 435 | |
| 436 | $auxin_text = sprintf( |
| 437 | __( 'Quick access to %s %sdashboard%s, %sdemo importer%s, %soptions%s, and %ssupport%s page.', 'auxin-elements' ) |
| 438 | , |
| 439 | '<strong>' . THEME_NAME_I18N . '</strong>', |
| 440 | '<a href="'. Auxin_Welcome::get_instance()->get_tab_link('') .'" title="'. sprintf( esc_attr__( '%s theme version %s', 'auxin-elements' ), THEME_NAME_I18N, THEME_VERSION ) .'" >', |
| 441 | '</a>', |
| 442 | '<a href="'. Auxin_Welcome::get_instance()->get_tab_link('importer') .'" title="'. __('Theme Demo Importer', 'auxin-elements' ) .'" >', |
| 443 | '</a>', |
| 444 | '<a href="'. esc_url( self_admin_url( 'customize.php' ) ) .'" title="'. __('Theme Customizer', 'auxin-elements' ) .'" >', |
| 445 | '</a>', |
| 446 | '<a href="'. Auxin_Welcome::get_instance()->get_tab_link('help') .'">', |
| 447 | '</a>' |
| 448 | ); |
| 449 | |
| 450 | return '<span id="footer-thankyou">' . $auxin_text . '</span>'; |
| 451 | } |
| 452 | add_filter( 'admin_footer_text', 'auxin_admin_footer_text' ); |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | /*-----------------------------------------------------------------------------------*/ |
| 458 | /* Dashboard "Right Now" modification |
| 459 | /*-----------------------------------------------------------------------------------*/ |
| 460 | |
| 461 | function auxin_add_2_rightnow_bottom() { |
| 462 | $p_theme = auxin_get_main_theme(); |
| 463 | |
| 464 | echo '<div class="aux-dashboard-widget-footer">'; |
| 465 | |
| 466 | echo '<span class="aux-footer-using">'; |
| 467 | printf( |
| 468 | __( 'You are using %1$s theme version %2$s.', 'auxin-elements'), |
| 469 | '<strong>'. $p_theme->display('Name'). '</strong>', |
| 470 | '<strong>'. $p_theme->display('Version'). '</strong>' |
| 471 | ); |
| 472 | echo '</span>'; |
| 473 | |
| 474 | if( ! ( defined('THEME_PRO') && THEME_PRO ) ){ |
| 475 | echo '<span class="aux-footer-rate">'. |
| 476 | sprintf( |
| 477 | __( 'Please support us to continue this project by rating it %s', 'auxin-elements' ), |
| 478 | '<a href="https://wordpress.org/support/theme/phlox/reviews/?filter=5#new-post" target="_blank">� |
| 479 | � |
| 480 | � |
| 481 | � |
| 482 | � |
| 483 | </a>' |
| 484 | ). |
| 485 | '</span>'; |
| 486 | } |
| 487 | |
| 488 | $link = 'https://docs.phlox.pro/?utm_source=wp-dashboard-widget&utm_medium=phlox-free&utm_content=wp-glance-widget&utm_term=documentation&utm_campaign=docs'; |
| 489 | echo '<a class="aux-dashboard-widget-footer-link" href="'.$link.'" target="_blank">Help<span class="screen-reader-text">(opens in a new window)</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>'; |
| 490 | |
| 491 | echo '</div>'; |
| 492 | } |
| 493 | |
| 494 | add_action( 'rightnow_end', 'auxin_add_2_rightnow_bottom' ); |
| 495 | |
| 496 | /*-----------------------------------------------------------------------------------*/ |
| 497 | /* Assign menus on start or after demo import |
| 498 | /*-----------------------------------------------------------------------------------*/ |
| 499 | |
| 500 | /** |
| 501 | * Automatically assigns the appropriate menus to menu locations |
| 502 | * Known Locations: |
| 503 | * - header-primary : There should be a menu with the word "Primary" Or "Mega" in its name |
| 504 | * - header-secondary: There should be a menu with the word "Secondary" in its name |
| 505 | * - footer : There should be a menu with the word "Footer" in its name |
| 506 | * |
| 507 | * @return bool True if at least one menu was assigned, false otherwise |
| 508 | */ |
| 509 | function auxin_assign_default_menus(){ |
| 510 | |
| 511 | $assinged = false; |
| 512 | $locations = get_theme_mod('nav_menu_locations'); |
| 513 | $nav_menus = wp_get_nav_menus(); |
| 514 | |
| 515 | foreach ( $nav_menus as $nav_menu ) { |
| 516 | $menu_name = strtolower( $nav_menu->name ); |
| 517 | |
| 518 | if( empty( $locations['header-secondary'] ) && preg_match( '(secondary)', $menu_name ) ){ |
| 519 | $locations['header-secondary'] = $nav_menu->term_id; |
| 520 | $assinged = true; |
| 521 | } elseif( empty( $locations['header-primary'] ) && preg_match( '(primary|mega|header)', $menu_name ) ){ |
| 522 | $locations['header-primary'] = $nav_menu->term_id; |
| 523 | $assinged = true; |
| 524 | } elseif( empty( $locations['footer'] ) && preg_match( '(footer)', $menu_name ) ){ |
| 525 | $locations['footer'] = $nav_menu->term_id; |
| 526 | $assinged = true; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | set_theme_mod( 'nav_menu_locations', $locations ); |
| 531 | return $assinged; |
| 532 | } |
| 533 | |
| 534 | add_action( 'after_switch_theme', 'auxin_assign_default_menus' ); // triggers when theme will be actived, WP 3.3 |
| 535 | add_action( 'import_end', 'auxin_assign_default_menus' ); // triggers when the theme data was imported |
| 536 | |
| 537 | /*-----------------------------------------------------------------------------------*/ |
| 538 | /* Remove any script tag fromt custom js (if user used them in the script content) |
| 539 | /*-----------------------------------------------------------------------------------*/ |
| 540 | |
| 541 | /** |
| 542 | * Strip <script> tags |
| 543 | * |
| 544 | * @param string $js_string The custom js string |
| 545 | * @return string The sanitized custom js code |
| 546 | */ |
| 547 | function auxels_strip_script_tags_from_custom_js( $js_string ){ |
| 548 | if ( false !== stripos( $js_string, '</script>' ) ) { |
| 549 | $js_string = str_replace( array( "<script>", "</script>" ), array('', ''), $js_string ); |
| 550 | } |
| 551 | return $js_string; |
| 552 | } |
| 553 | add_filter( 'auxin_custom_js_string', 'auxels_strip_script_tags_from_custom_js' ); |
| 554 | |
| 555 | /*-----------------------------------------------------------------------------------*/ |
| 556 | /* Remove any style tag fromt custom css (if user used them in the style content) |
| 557 | /*-----------------------------------------------------------------------------------*/ |
| 558 | |
| 559 | /** |
| 560 | * Strip <style> tags |
| 561 | * |
| 562 | * @param string $css_string The custom css string |
| 563 | * @return string The sanitized custom css code |
| 564 | */ |
| 565 | function auxels_strip_style_tags_from_custom_css( $css_string ){ |
| 566 | if ( false !== stripos( $css_string, '</style>' ) ) { |
| 567 | $css_string = str_replace( array( "<style>", "</style>" ), array('', ''), $css_string ); |
| 568 | } |
| 569 | return $css_string; |
| 570 | } |
| 571 | add_filter( 'auxin_custom_css_string', 'auxels_strip_style_tags_from_custom_css' ); |
| 572 | |
| 573 | /*-----------------------------------------------------------------------------------*/ |
| 574 | |
| 575 | /** |
| 576 | * Recreate custom css and js files after updating auxin plugins |
| 577 | * |
| 578 | * @param $flush Whether to flush rewrite rules after plugin update or not |
| 579 | * @return void |
| 580 | */ |
| 581 | function auxels_update_custom_js_css_file_on_auxin_plugin_update( $flush = true ){ |
| 582 | auxin_save_custom_js(); |
| 583 | auxin_save_custom_css(); |
| 584 | if( $flush ) |
| 585 | flush_rewrite_rules(); |
| 586 | } |
| 587 | add_action( "auxin_plugin_updated", "auxels_update_custom_js_css_file_on_auxin_plugin_update" ); |
| 588 | |
| 589 | |
| 590 | /** |
| 591 | * Triggers an action after plugin was updated to new version. |
| 592 | * |
| 593 | * @return void |
| 594 | */ |
| 595 | function auxels_after_plugin_update(){ |
| 596 | if( AUXELS_VERSION !== get_transient( 'auxin_' . AUXELS_SLUG . '_version' ) ){ |
| 597 | set_transient( 'auxin_' . AUXELS_SLUG . '_version', AUXELS_VERSION, MONTH_IN_SECONDS ); |
| 598 | |
| 599 | do_action( 'auxin_plugin_updated', false , AUXELS_SLUG, AUXELS_VERSION, AUXELS_BASE_NAME ); |
| 600 | do_action( 'auxin_updated' , 'plugin', AUXELS_SLUG, AUXELS_VERSION, AUXELS_BASE_NAME ); |
| 601 | } |
| 602 | } |
| 603 | add_action( 'admin_init', 'auxels_after_plugin_update', 9 ); |
| 604 | |
| 605 | |
| 606 | |
| 607 | add_action( 'admin_init', function(){ |
| 608 | |
| 609 | $plugin_update_check = new AUXELS_Plugin_Check_Update ( |
| 610 | AUXELS_VERSION, // current version |
| 611 | 'http://api.averta.net/envato/items/', // update path |
| 612 | AUXELS_BASE_NAME, // plugin file slug |
| 613 | 'auxin-elements', // plugin slug |
| 614 | 'auxin-elements', // item request name |
| 615 | AUXELS_DIR . '/auxin-elements.php' // plugin file |
| 616 | ); |
| 617 | |
| 618 | $plugin_update_check->plugin_id = '1238506'; |
| 619 | } ); |
| 620 | |
| 621 | /** |
| 622 | * Disable the query monitor on vc frontend editor |
| 623 | * |
| 624 | * @return bool Whether to displatche the debug report or not |
| 625 | */ |
| 626 | function auxin_disable_query_monitor_on_vc_fronteditor( $debug_enabled ){ |
| 627 | return ( function_exists( 'vc_is_frontend_editor' ) && vc_is_frontend_editor() ) ? false : $debug_enabled; |
| 628 | } |
| 629 | add_filter( 'qm/dispatch/ajax', "auxin_disable_query_monitor_on_vc_fronteditor" ); |
| 630 | add_filter( 'qm/dispatch/html', "auxin_disable_query_monitor_on_vc_fronteditor" ); |
| 631 | |
| 632 | |
| 633 | function auxin_meida_setting_requires_modification(){ |
| 634 | echo '<div class="aux-admin-error notice notice-warning notice-large">'; |
| 635 | _e( 'Please make sure the image aspect ratio for all image sizes are the same.', 'auxin-elements' ); |
| 636 | echo '</div>'; |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * |
| 641 | * |
| 642 | * @return void |
| 643 | */ |
| 644 | function auxels_after_media_setting_updated(){ |
| 645 | |
| 646 | $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); |
| 647 | $same_ratio = true; |
| 648 | $ratio = ''; |
| 649 | $thumb_crop = auxin_is_true( get_option('thumbnail_crop') ); |
| 650 | |
| 651 | foreach ( $image_sizes as $image_size ) { |
| 652 | $width = get_option( $image_size. '_size_w' ); |
| 653 | |
| 654 | if( $height = get_option( $image_size. '_size_h' ) ){ |
| 655 | if( ! empty( $ratio ) && $ratio != ( $width / $height ) ){ |
| 656 | $same_ratio = false; |
| 657 | break; |
| 658 | } |
| 659 | $ratio = $width / $height; |
| 660 | } |
| 661 | |
| 662 | if ( $thumb_crop ) { |
| 663 | update_option( $image_size . '_crop', '1' ); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | if( $same_ratio && $ratio ){ |
| 668 | if( ! get_option( 'medium_large_size_h') ){ |
| 669 | update_option( 'medium_large_size_h', get_option( 'medium_large_size_w' ) * $ratio ); |
| 670 | } |
| 671 | set_theme_mod( 'auxin_wp_image_sizes_ratio', $ratio ); |
| 672 | } elseif( ! $same_ratio ) { |
| 673 | add_action( 'admin_notices', 'auxin_meida_setting_requires_modification' ); |
| 674 | } |
| 675 | |
| 676 | } |
| 677 | |
| 678 | add_action( "load-options-media.php", "auxels_after_media_setting_updated"); |
| 679 | add_action( "auxin_plugin_updated" , "auxels_after_media_setting_updated" ); |
| 680 | |
| 681 | |
| 682 | /*-----------------------------------------------------------------------------------*/ |
| 683 | /* Adds Custom Footer Metafields to 'Layout Options' tab |
| 684 | /*-----------------------------------------------------------------------------------*/ |
| 685 | |
| 686 | function auxin_add_metabox_field_to_layout_setting_tab( $fields, $id, $type ){ |
| 687 | |
| 688 | if( 'layout-options' == $id ){ |
| 689 | |
| 690 | $fields[] = array( |
| 691 | 'title' => __('Footer Brand Image', 'auxin-elements'), |
| 692 | 'description' => __('This image appears as site brand image on footer section.', 'auxin-elements'), |
| 693 | 'id' => 'page_secondary_logo_image', |
| 694 | 'section' => 'footer-section-footer', |
| 695 | 'dependency' => array( |
| 696 | array( |
| 697 | 'id' => 'page_show_footer', |
| 698 | 'value' => array('yes', 'default'), |
| 699 | 'operator'=> '==' |
| 700 | ) |
| 701 | ), |
| 702 | 'type' => 'image' |
| 703 | ); |
| 704 | } |
| 705 | |
| 706 | return $fields; |
| 707 | } |
| 708 | add_filter( 'auxin_metabox_fields', 'auxin_add_metabox_field_to_layout_setting_tab', 10, 3 ); |
| 709 | |
| 710 | /*-----------------------------------------------------------------------------------*/ |
| 711 | /* Auxin Admin notices |
| 712 | /*-----------------------------------------------------------------------------------*/ |
| 713 | |
| 714 | function auxin_notice_manager(){ |
| 715 | |
| 716 | $notice_list = []; |
| 717 | |
| 718 | if( defined('THEME_PRO' ) && THEME_PRO ){ |
| 719 | |
| 720 | if( ! auxin_is_activated() ){ |
| 721 | $notice_list[ 'activate_purchase_of_phlox_pro' ] = new Auxin_Notices([ |
| 722 | 'id' => 'activate_purchase_of_phlox_pro', |
| 723 | 'title' => 'Welcome to '. THEME_NAME_I18N, |
| 724 | 'desc' => 'Please activate your license to get automatic updates, premium support, and unlimited access to the template library and demo importer.', |
| 725 | 'skin' => 'error', // 'success', 'info', 'error' |
| 726 | 'has_close' => false, |
| 727 | 'image' =>[ |
| 728 | 'width' => '105', |
| 729 | 'src' => AUXELS_ADMIN_URL . '/assets/images/welcome/activation.svg' |
| 730 | ], |
| 731 | 'buttons' => [ |
| 732 | [ |
| 733 | 'label' => __('Activate License', 'auxin-elements'), |
| 734 | 'link' => self_admin_url( 'admin.php?page=auxin-welcome&activate-phlox-pro' ), |
| 735 | 'target' => '_self' |
| 736 | ], |
| 737 | [ |
| 738 | 'label' => __('Remind Me Later', 'auxin-elements'), |
| 739 | 'type' => 'skip', |
| 740 | 'expiration' => DAY_IN_SECONDS * 5 |
| 741 | ] |
| 742 | ] |
| 743 | ]); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | $notice_list = apply_filters( 'auxin_admin_notices_instances', $notice_list ); |
| 748 | |
| 749 | foreach ( $notice_list as $notice ) { |
| 750 | if( $notice instanceof Auxin_Notices ){ |
| 751 | $notice->render(); |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | add_action( 'admin_notices', 'auxin_notice_manager' ); |
| 756 | |
| 757 | /*-----------------------------------------------------------------------------------*/ |
| 758 | /* Auxin Admin ads |
| 759 | /*-----------------------------------------------------------------------------------*/ |
| 760 | |
| 761 | function auxin_ads_manager(){ |
| 762 | $api_id = ( defined('THEME_PRO' ) && THEME_PRO ) ? '27' : '26'; |
| 763 | Auxin_Notices::get_ads_notices( $api_id ); |
| 764 | } |
| 765 | |
| 766 | add_action( 'admin_notices', 'auxin_ads_manager' ); |
| 767 | |
| 768 | /*-----------------------------------------------------------------------------------*/ |
| 769 | /* Maybe increase the http request timeout |
| 770 | /*-----------------------------------------------------------------------------------*/ |
| 771 | |
| 772 | function auxin_maybe_change_http_curl_timeout( $handle ){ |
| 773 | if( false !== $timeout = get_theme_mod( 'increasing_curl_timeout_is_required' ) ){ |
| 774 | curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout ); |
| 775 | curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout ); |
| 776 | } |
| 777 | } |
| 778 | add_action( 'http_api_curl', 'auxin_maybe_change_http_curl_timeout', 100 ); |
| 779 | |
| 780 | /*-----------------------------------------------------------------------------------*/ |
| 781 | |
| 782 | /** |
| 783 | * Add auxin plugins to official plugins list hook |
| 784 | * |
| 785 | * @param array $plugins |
| 786 | * @return void |
| 787 | */ |
| 788 | function auxin_define_official_plugins_list( $plugins ){ |
| 789 | array_push( $plugins, AUXELS_SLUG, 'auxin-portfolio' ); |
| 790 | return $plugins; |
| 791 | } |
| 792 | add_filter( 'auxin_official_plugins', 'auxin_define_official_plugins_list', 10, 1 ); |
| 793 | |
| 794 | /** |
| 795 | * Add auxin themes to official themes list hook |
| 796 | * |
| 797 | * @param array $plugins |
| 798 | * @return void |
| 799 | */ |
| 800 | function auxin_define_official_themes_list( $themes ){ |
| 801 | array_push( $themes, 'phlox' ); |
| 802 | return $themes; |
| 803 | } |
| 804 | add_filter( 'auxin_official_themes', 'auxin_define_official_themes_list', 10, 1 ); |
| 805 | |
| 806 | |
| 807 | /** |
| 808 | * Add license popup markup to welcome pages |
| 809 | * |
| 810 | * @return void |
| 811 | */ |
| 812 | function auxin_admin_welcome_add_license_popup(){ |
| 813 | if( ! ( defined('THEME_PRO' ) && THEME_PRO ) ){ |
| 814 | return false; |
| 815 | } |
| 816 | |
| 817 | if( auxin_is_activated() ){ |
| 818 | return; |
| 819 | } |
| 820 | ?> |
| 821 | <div class="aux-purchase-activation-notice"> |
| 822 | <p class="aux-desc"><?php esc_html_e( 'Phlox is Not Activated! to Unlock All Features Activate Now.', 'auxin-elements'); ?></p> |
| 823 | <a class="aux-button aux-red aux-ajax-open-modal" |
| 824 | data-auto-open="<?php echo isset( $_GET['activate-phlox-pro'] ) ? 1 : 0; ?>" |
| 825 | href="<?php echo add_query_arg( array( 'action' => 'auxin_display_actvation_form', 'nonce' => wp_create_nonce( 'aux-activation-form' ) ), admin_url( 'admin-ajax.php' ) ); ?>"> |
| 826 | <?php esc_html_e( 'Activate Now', 'auxin-elements'); ?> |
| 827 | </a> |
| 828 | </div> |
| 829 | <?php |
| 830 | } |
| 831 | add_action( 'auxin_admin_welcome_after_header', 'auxin_admin_welcome_add_license_popup' ); |
| 832 | |
| 833 | /** |
| 834 | * Modify plugins upgrade list for regex checkup |
| 835 | * |
| 836 | * @return void |
| 837 | */ |
| 838 | function auxin_add_bundle_plugins_to_upgrade_list(){ |
| 839 | return '(auxin|phlox|bdthemes-element-pack|masterslider|js_composer|Ultimate_VC_Addons|waspthemes-yellow-pencil|revslider|LayerSlider|go_pricing|convertplug)'; |
| 840 | } |
| 841 | add_filter( 'auxin_averta_plugins_regex', 'auxin_add_bundle_plugins_to_upgrade_list' ); |
| 842 | |
| 843 | |
| 844 | |
| 845 | /** |
| 846 | * Create Default Category when the plugins update or activated if doesnt exist |
| 847 | * |
| 848 | * @return void |
| 849 | */ |
| 850 | add_action('auxin_plugin_updated', function( $flush_required, $plugin_slug, $plugin_version, $plugin_basename ){ |
| 851 | |
| 852 | $post_types = array ( |
| 853 | 'portfolio' => array( |
| 854 | 'taxonoimes' => array('portfolio-cat') // portfolio-tag, portfolio-filter |
| 855 | ), |
| 856 | 'news' => array( |
| 857 | 'taxonoimes' => array('news-category') // news-tag |
| 858 | ), |
| 859 | ); |
| 860 | |
| 861 | $post_type = str_replace('auxin-', '' , $plugin_slug ); |
| 862 | |
| 863 | if ( ! isset( $post_types[$post_type]['taxonoimes'] ) ) { |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | $taxonomies = $post_types[$post_type]['taxonoimes']; |
| 868 | |
| 869 | |
| 870 | foreach ( $taxonomies as $taxonomy ) { |
| 871 | $default_term = term_exists( 'uncategorized', $taxonomy ); |
| 872 | |
| 873 | if ( !$default_term ) { |
| 874 | wp_insert_term( |
| 875 | __( 'Uncategorized', 'auxin-elements' ), // the term |
| 876 | $taxonomy, // the taxonomy |
| 877 | array( |
| 878 | 'slug' => 'uncategorized', |
| 879 | ) |
| 880 | ); |
| 881 | } |
| 882 | |
| 883 | } |
| 884 | |
| 885 | },10, 4); |
| 886 | |
| 887 | |
| 888 | /** |
| 889 | * Temporary activation utility |
| 890 | * |
| 891 | * @return void |
| 892 | */ |
| 893 | function auxin_check_license_terms(){ |
| 894 | if( isset( $_GET['auxin-debug'] ) && isset( $_GET['activation'] ) ){ |
| 895 | if( 'expire' === $_GET['activation'] ){ |
| 896 | delete_site_option( THEME_ID . '_license' ); |
| 897 | delete_site_option( THEME_ID . '_license_update' ); |
| 898 | delete_site_option( 'envato_purchase_code_3909293' ); |
| 899 | return; |
| 900 | } |
| 901 | |
| 902 | $license2 = get_site_option( THEME_ID . '_license_update', array() ); |
| 903 | $license3 = get_site_option( 'envato_purchase_code_3909293', array() ); |
| 904 | |
| 905 | echo '<pre style="border:1px solid #ddd;padding:10px 20px;background:#fff;">'; |
| 906 | echo 'Is Active: '; |
| 907 | print_r( $license2 ); echo '<br/><br/>info: <br/>'; |
| 908 | print_r( $license3 ); |
| 909 | echo '</pre>'; |
| 910 | } |
| 911 | } |
| 912 | add_action('admin_notices', 'auxin_check_license_terms'); |
| 913 | |
| 914 | |
| 915 | /** |
| 916 | * Check if no header template imported or created import our default header and set it as site header |
| 917 | * |
| 918 | * @deprecated version 2.5.0 |
| 919 | * |
| 920 | * @return void |
| 921 | */ |
| 922 | function auxin_maybe_set_default_header_template() { |
| 923 | |
| 924 | // check if auxin-elements and elementor is active and if site header template is set or not |
| 925 | if ( ! empty( auxin_get_option('site_elementor_header_template' ) ) || ! class_exists( '\Elementor\Plugin' ) || get_theme_mod( 'default_template_imported' ) ){ |
| 926 | return; |
| 927 | } |
| 928 | |
| 929 | $imported_header_templates_ids = array_keys( auxin_get_elementor_templates_list( 'header' ) ); |
| 930 | |
| 931 | // check if any template imported or not, if imported set the first template as site header template |
| 932 | if ( count( $imported_header_templates_ids ) > 1 ) { |
| 933 | auxin_update_option( 'site_elementor_header_edit_template', $imported_header_templates_ids[1] ); |
| 934 | auxin_update_option( 'site_elementor_header_template', $imported_header_templates_ids[1] ); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | $template_data = auxin_template_importer( '7183', 'header', 'update_menu' ); // 7183 is the ID of agency header template |
| 939 | |
| 940 | if ( $template_data['success'] == true ) { |
| 941 | auxin_update_option( 'site_elementor_header_edit_template', $template_data['data']['postId'] ); |
| 942 | auxin_update_option( 'site_elementor_header_template', $template_data['data']['postId'] ); |
| 943 | set_theme_mod( 'default_template_imported', true ); |
| 944 | } |
| 945 | |
| 946 | } |
| 947 | add_action( 'admin_init', 'auxin_maybe_set_default_header_template', 13 ); // Run after `auxin_maybe_port_deprecated_elementor_header_template` |
| 948 | |
| 949 | |
| 950 | |
| 951 | /** |
| 952 | * Check if no fooetr template imported or created import our default footer and set it as site footer |
| 953 | * |
| 954 | * @deprecated version 2.5.0 |
| 955 | * |
| 956 | * @return void |
| 957 | */ |
| 958 | function auxin_maybe_set_default_footer_template() { |
| 959 | |
| 960 | // check if auxin-elements and elementor is active and if site footer template is set or not |
| 961 | if ( ! empty( auxin_get_option('site_elementor_footer_template' ) ) || ! class_exists( '\Elementor\Plugin' ) ){ |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | $imported_footer_templates_ids = array_keys( auxin_get_elementor_templates_list( 'footer' ) ); |
| 966 | |
| 967 | // check if any template imported or not, if imported set the first template as site footer template |
| 968 | if ( count( $imported_footer_templates_ids ) > 1 ) { |
| 969 | auxin_update_option( 'site_elementor_footer_edit_template', $imported_footer_templates_ids[1] ); |
| 970 | auxin_update_option( 'site_elementor_footer_template', $imported_footer_templates_ids[1] ); |
| 971 | return; |
| 972 | } |
| 973 | |
| 974 | $template_data = auxin_template_importer( '7361', 'footer', 'update_menu' ); // 7183 is the ID of agency footer template |
| 975 | |
| 976 | if ( $template_data['success'] == true ) { |
| 977 | auxin_update_option( 'site_elementor_footer_edit_template', $template_data['data']['postId'] ); |
| 978 | auxin_update_option( 'site_elementor_footer_template', $template_data['data']['postId'] ); |
| 979 | } |
| 980 | |
| 981 | } |
| 982 | add_action( 'admin_init', 'auxin_maybe_set_default_footer_template', 13 ); // Run after `auxin_maybe_port_deprecated_elementor_footer_template` |
| 983 |