classes
8 years ago
compatibility
8 years ago
metaboxes
8 years ago
modules
9 years ago
admin-ajax.php
8 years ago
admin-hooks.php
8 years ago
admin-the-functions.php
8 years ago
index.php
8 years ago
admin-hooks.php
481 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 axion_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", "axion_init_shortcode_manager"); |
| 38 | |
| 39 | /*-----------------------------------------------------------------------------------*/ |
| 40 | /* Add Editor styles |
| 41 | /*-----------------------------------------------------------------------------------*/ |
| 42 | |
| 43 | function auxin_register_mce_buttons_style(){ |
| 44 | wp_register_style('auxin_mce_buttons' , AUXELS_ADMIN_URL. '/assets/css/editor.css', NULL, '1.1'); |
| 45 | wp_enqueue_style('auxin_mce_buttons'); |
| 46 | } |
| 47 | add_action('admin_enqueue_scripts', 'auxin_register_mce_buttons_style'); |
| 48 | |
| 49 | |
| 50 | |
| 51 | /*-----------------------------------------------------------------------------------*/ |
| 52 | /* Adds demos tab in theme about (welcome) page |
| 53 | /*-----------------------------------------------------------------------------------*/ |
| 54 | |
| 55 | function auxin_welcome_page_display_section_demos(){ |
| 56 | // all the demos information should add into this array |
| 57 | $demos_list = auxin_get_demo_info_list(); |
| 58 | |
| 59 | if( ! empty( $demos_list ) ){ |
| 60 | $wpnonce = wp_create_nonce( 'auxin-import' ); |
| 61 | ?> |
| 62 | <h2 class="aux-featur"><?php _e('Choose the demo you want.', 'auxin-elements'); ?></h2> |
| 63 | <h4 class="aux-featur demos-subtitle"><?php _e('Please note that, it is recommended to import a demo on a clean WordPress installation.', 'auxin-elements'); ?></h4> |
| 64 | <div class="changelog feature-section three-col"> |
| 65 | <?php |
| 66 | foreach( $demos_list as $demo_id => $demo_info ){ |
| 67 | ?> |
| 68 | <div class="col" id="<?php echo esc_attr( $demo_info['id'] ); ?>"> |
| 69 | <img class="demos-img" src="<?php echo esc_attr( $demo_info['thumb_url'] ); ?>" alt="<?php echo esc_attr( $demo_info['title'] ); ?>"> |
| 70 | <h3><?php echo $demo_info['title']; ?></h3> |
| 71 | <p><?php echo $demo_info['desc' ]; ?></p> |
| 72 | <a href="<?php echo esc_url( $demo_info['preview_url'] ); ?>" class="button button-primary aux-button" target="_blank"><?php _e('Preview', 'auxin-elements'); ?></a> |
| 73 | <a href="<?php echo admin_url( 'import.php?import=auxin-importer&demo-id=' . $demo_id. '&_wpnonce=' . $wpnonce ); ?>" class="button button-primary aux-button import-demo"> |
| 74 | <?php _e( 'Import Demo', 'auxin-elements' ); ?> |
| 75 | </a> |
| 76 | </div> |
| 77 | <?php |
| 78 | } |
| 79 | echo '</div>'; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | function auxin_welcome_add_section_demos( $sections ){ |
| 84 | |
| 85 | $sections['demos'] = array( |
| 86 | 'label' => __( 'Demos', 'auxin-elements' ), |
| 87 | 'description' => sprintf(__( 'you can see and import the %s demos in this section.', 'auxin-elements'), THEME_NAME_I18N ), |
| 88 | 'callback' => 'auxin_welcome_page_display_section_demos' |
| 89 | ); |
| 90 | |
| 91 | return $sections; |
| 92 | } |
| 93 | |
| 94 | add_filter( 'auxin_admin_welcome_sections', 'auxin_welcome_add_section_demos', 60 ); |
| 95 | |
| 96 | /*-----------------------------------------------------------------------------------*/ |
| 97 | /* Adds system status tab in theme about (welcome) page |
| 98 | /*-----------------------------------------------------------------------------------*/ |
| 99 | |
| 100 | function auxin_about_system_status( $sections ){ |
| 101 | |
| 102 | $sections['status'] = array( |
| 103 | 'label' => __( 'System Status', 'auxin-elements' ), |
| 104 | 'description' => __( 'The informaition about your WordPress installation which can be helpful for debugging or monitoring your website.', 'auxin-elements'), |
| 105 | 'callback' => 'auxin_get_about_system_status' |
| 106 | ); |
| 107 | |
| 108 | return $sections; |
| 109 | } |
| 110 | |
| 111 | add_filter( 'auxin_admin_welcome_sections', 'auxin_about_system_status', 100 ); |
| 112 | |
| 113 | |
| 114 | /*-----------------------------------------------------------------------------------*/ |
| 115 | /* Adds feedback tab in theme about (welcome) page |
| 116 | /*-----------------------------------------------------------------------------------*/ |
| 117 | |
| 118 | function auxin_welcome_page_display_section_feedback(){ |
| 119 | // the previous rate of the client |
| 120 | $previous_rate = auxin_get_option( 'user_rating' ); |
| 121 | $support_tab_url = admin_url( 'themes.php?page=auxin-welcome&tab=support' ); |
| 122 | ?> |
| 123 | |
| 124 | <div class="changelog feature-section two-col feedback"> |
| 125 | |
| 126 | <form class="aux-feedback-form" action="<?php echo admin_url( 'admin.php?page=auxin-welcome&tab=feedback'); ?>" method="post" > |
| 127 | |
| 128 | <div class="aux-rating-section"> |
| 129 | <h2 class="aux-featur"><?php _e('How likely are you to recommend Phlox to a friend?', 'auxin-elements' ); ?></h2> |
| 130 | <div class="aux-theme-ratings"> |
| 131 | <?php |
| 132 | for( $i = 1; $i <= 5; $i++ ){ |
| 133 | printf( |
| 134 | '<div class="aux-rate-cell"><input type="radio" name="theme_rate" id="theme-rating%1$s" value="%1$s" %2$s/><label class="rating" for="theme-rating%1$s">%1$s</label></div>', |
| 135 | $i, checked( $previous_rate, $i, false ) |
| 136 | ); |
| 137 | } |
| 138 | ?> |
| 139 | |
| 140 | </div> |
| 141 | <div class="aux-ratings-measure"> |
| 142 | <p>Don't like it</p> |
| 143 | <p>Like it so much</p> |
| 144 | </div> |
| 145 | </div> |
| 146 | |
| 147 | <div class="aux-feedback-section aux-hide"> |
| 148 | <h2 class="aux-featur"><?php _e('Please explain why you gave this score (optional)', 'auxin-elements'); ?></h2> |
| 149 | <h4 class="aux-featur feedback-subtitle"> |
| 150 | <?php |
| 151 | printf( __( 'Please do not use this form to get support, in this case please check the %s help section %s', 'auxin-elements' ), |
| 152 | '<a href="' . $support_tab_url . '">', '</a>' ); ?> |
| 153 | </h4> |
| 154 | <textarea placeholder="Enter your feedback here" rows="10" name="feedback" class="large-text"></textarea> |
| 155 | <input type="text" placeholder="Email address (Optional)" name="email" class="text-input" /> |
| 156 | <?php wp_nonce_field( 'phlox_feedback' ); ?> |
| 157 | |
| 158 | <input type="submit" class="button button-primary aux-button" value="Submit feedback" /> |
| 159 | |
| 160 | <div class="aux-sending-status"> |
| 161 | <img class="ajax-progress aux-hide" src="<?php echo AUXIN_URL; ?>/css/images/elements/saving.gif" /> |
| 162 | <span class="ajax-response aux-hide" ><?php _e( 'Submitting your feedback ..', 'auxin-elements' ); ?></span> |
| 163 | </div> |
| 164 | |
| 165 | </div> |
| 166 | |
| 167 | <?php auxin_send_feedback_mail(); ?> |
| 168 | </form> |
| 169 | </div> |
| 170 | |
| 171 | <?php |
| 172 | } |
| 173 | |
| 174 | function auxin_welcome_add_section_feedback( $sections ){ |
| 175 | |
| 176 | $sections['feedback'] = array( |
| 177 | 'label' => __( 'Feedback', 'auxin-elements' ), |
| 178 | 'description' => sprintf(__( 'Please leave a feedback and help us to improve %s theme.', 'auxin-elements'), THEME_NAME_I18N ), |
| 179 | 'callback' => 'auxin_welcome_page_display_section_feedback' |
| 180 | ); |
| 181 | |
| 182 | return $sections; |
| 183 | } |
| 184 | |
| 185 | add_filter( 'auxin_admin_welcome_sections', 'auxin_welcome_add_section_feedback', 90 ); |
| 186 | |
| 187 | function auxin_send_feedback_mail(){ |
| 188 | if ( ! ( ! isset( $_POST['phlox_feedback'] ) || ! wp_verify_nonce( $_POST['phlox_feedback'], 'feedback_send') ) ) { |
| 189 | |
| 190 | $email = ! empty( $_POST["email"] ) ? sanitize_email( $_POST["email"] ) : 'Empty'; |
| 191 | $feedback = ! empty( $_POST["feedback"] ) ? esc_textarea( $_POST["feedback"] ) : ''; |
| 192 | |
| 193 | if( $feedback ){ |
| 194 | wp_mail( 'info@averta.net', 'feedback from phlox dashboard', $feedback . chr(0x0D).chr(0x0A) . 'Email: ' . $email ); |
| 195 | $text = __( 'Thanks for your feedback', 'auxin-elements' ); |
| 196 | } else{ |
| 197 | $text = __('Please try again and fill up at least the feedback field.', 'auxin-elements'); |
| 198 | } |
| 199 | |
| 200 | printf('<p class="notification">%s</p>', $text); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /*-----------------------------------------------------------------------------------*/ |
| 205 | /* Adds subtitle meta field to 'Title setting' tab |
| 206 | /*-----------------------------------------------------------------------------------*/ |
| 207 | |
| 208 | function auxin_add_metabox_field_to_title_setting_tab( $fields, $id, $type ){ |
| 209 | |
| 210 | if( 'general-title' == $id ){ |
| 211 | array_unshift( |
| 212 | $fields, |
| 213 | array( |
| 214 | 'title' => __('Subtitle', 'auxin-elements'), |
| 215 | 'description' => __('Second Title (optional). Note: You have to enable "Display Title Bar Section" option in order to display the subtitle.', 'auxin-elements'), |
| 216 | 'id' => 'page_subtitle', |
| 217 | 'type' => 'editor', |
| 218 | 'default' => '' |
| 219 | ) |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | return $fields; |
| 224 | } |
| 225 | add_filter( 'auxin_metabox_fields', 'auxin_add_metabox_field_to_title_setting_tab', 10, 3 ); |
| 226 | |
| 227 | |
| 228 | /*-----------------------------------------------------------------------------------*/ |
| 229 | /* Adds Custom JavaScript meta field to 'Advanced setting' tab |
| 230 | /*-----------------------------------------------------------------------------------*/ |
| 231 | |
| 232 | function auxin_add_metabox_field_to_advanced_setting_tab( $fields, $id, $type ){ |
| 233 | |
| 234 | if( 'general-advanced' == $id ){ |
| 235 | $fields[] = array( |
| 236 | 'title' => __('Custom JavaScript Code', 'auxin-elements'), |
| 237 | 'description' => __('Attention: The following custom JavaScript code will be applied ONLY to this page.', 'auxin-elements').'<br />'. |
| 238 | __('For defining global JavaScript roles, please use custom javaScript field on option panel.', 'auxin-elements' ), |
| 239 | 'id' => 'aux_page_custom_js', |
| 240 | 'type' => 'code', |
| 241 | 'mode' => 'javascript', |
| 242 | 'default' => '' |
| 243 | ); |
| 244 | } |
| 245 | return $fields; |
| 246 | } |
| 247 | add_filter( 'auxin_metabox_fields', 'auxin_add_metabox_field_to_advanced_setting_tab', 10, 3 ); |
| 248 | |
| 249 | |
| 250 | /*-----------------------------------------------------------------------------------*/ |
| 251 | /* Adding fallback for deprecated theme option name |
| 252 | /*-----------------------------------------------------------------------------------*/ |
| 253 | |
| 254 | function auxels_sync_deprecated_options(){ |
| 255 | |
| 256 | $old_theme_options = get_option( THEME_ID . '_formatted_options' ); |
| 257 | if( false === $old_theme_options ){ |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | $new_theme_options = get_option( THEME_ID . '_theme_options' ); |
| 262 | if( false === $new_theme_options ){ |
| 263 | update_option( THEME_ID . '_theme_options', $old_theme_options ); |
| 264 | } |
| 265 | } |
| 266 | add_action( 'admin_init', 'auxels_sync_deprecated_options' ); |
| 267 | |
| 268 | /*-----------------------------------------------------------------------------------*/ |
| 269 | /* Add allowed custom mieme types |
| 270 | /*-----------------------------------------------------------------------------------*/ |
| 271 | |
| 272 | function auxin_mime_types( $mimes ) { |
| 273 | $mimes['svg'] = 'image/svg+xml'; |
| 274 | return $mimes; |
| 275 | } |
| 276 | |
| 277 | add_filter('upload_mimes', 'auxin_mime_types'); |
| 278 | |
| 279 | |
| 280 | /*-----------------------------------------------------------------------------------*/ |
| 281 | /* Add post format related metafields to post |
| 282 | /*-----------------------------------------------------------------------------------*/ |
| 283 | |
| 284 | function auxels_add_post_metabox_models( $models ){ |
| 285 | |
| 286 | // Load general metabox models |
| 287 | include_once( 'metaboxes/metabox-fields-post-audio.php' ); |
| 288 | include_once( 'metaboxes/metabox-fields-post-gallery.php' ); |
| 289 | include_once( 'metaboxes/metabox-fields-post-quote.php' ); |
| 290 | include_once( 'metaboxes/metabox-fields-post-video.php' ); |
| 291 | |
| 292 | $models[] = array( |
| 293 | 'model' => auxin_metabox_fields_post_gallery(), |
| 294 | 'priority' => 20 |
| 295 | ); |
| 296 | |
| 297 | $models[] = array( |
| 298 | 'model' => auxin_metabox_fields_post_video(), |
| 299 | 'priority' => 22 |
| 300 | ); |
| 301 | |
| 302 | $models[] = array( |
| 303 | 'model' => auxin_metabox_fields_post_audio(), |
| 304 | 'priority' => 24 |
| 305 | ); |
| 306 | |
| 307 | $models[] = array( |
| 308 | 'model' => auxin_metabox_fields_post_quote(), |
| 309 | 'priority' => 26 |
| 310 | ); |
| 311 | |
| 312 | $models[] = array( |
| 313 | 'model' => auxin_metabox_fields_general_advanced(), |
| 314 | 'priority' => 36 |
| 315 | ); |
| 316 | |
| 317 | return $models; |
| 318 | } |
| 319 | |
| 320 | add_filter( 'auxin_admin_metabox_models_post', 'auxels_add_post_metabox_models' ); |
| 321 | |
| 322 | /*-----------------------------------------------------------------------------------*/ |
| 323 | /* Add advanced metafields to page |
| 324 | /*-----------------------------------------------------------------------------------*/ |
| 325 | |
| 326 | function auxels_add_page_metabox_models( $models ){ |
| 327 | |
| 328 | |
| 329 | $models[] = array( |
| 330 | 'model' => auxin_metabox_fields_general_advanced(), |
| 331 | 'priority' => 36 |
| 332 | ); |
| 333 | |
| 334 | return $models; |
| 335 | } |
| 336 | |
| 337 | add_filter( 'auxin_admin_metabox_models_page', 'auxels_add_page_metabox_models' ); |
| 338 | |
| 339 | /*-----------------------------------------------------------------------------------*/ |
| 340 | /* Add theme tab in siteorigin page builder |
| 341 | /*-----------------------------------------------------------------------------------*/ |
| 342 | |
| 343 | function auxin_add_widget_tabs($tabs) { |
| 344 | $tabs[] = array( |
| 345 | 'title' => THEME_NAME, |
| 346 | 'filter' => array( |
| 347 | 'groups' => array('auxin') |
| 348 | ) |
| 349 | ); |
| 350 | |
| 351 | if (isset($tabs['recommended'])){ |
| 352 | unset($tabs['recommended']); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | return $tabs; |
| 357 | } |
| 358 | add_filter( 'siteorigin_panels_widget_dialog_tabs', 'auxin_add_widget_tabs', 20 ); |
| 359 | |
| 360 | // ============================================================================= |
| 361 | |
| 362 | function auxin_admin_footer_text( $footer_text ) { |
| 363 | |
| 364 | // the admin pages that we intent to display theme footer text on |
| 365 | $admin_pages = array( |
| 366 | 'toplevel_page_auxin', |
| 367 | 'appearance_page_auxin', |
| 368 | 'toplevel_page_auxin-welcome', |
| 369 | 'appearance_page_auxin-welcome', |
| 370 | 'page', |
| 371 | 'post', |
| 372 | 'widgets', |
| 373 | 'dashboard', |
| 374 | 'edit-post', |
| 375 | 'edit-page', |
| 376 | 'edit-portfolio' |
| 377 | ); |
| 378 | |
| 379 | if( ! ( function_exists('auxin_is_theme_admin_page') && auxin_is_theme_admin_page( $admin_pages ) ) ){ |
| 380 | return $footer_text; |
| 381 | } |
| 382 | |
| 383 | $welcome_tab_url = admin_url( 'themes.php?page=auxin-welcome&tab=' ); |
| 384 | |
| 385 | $auxin_text = sprintf( |
| 386 | __( 'Quick access to %sdashboard%s, %soptions%s, %ssupport%s and %sfeedback%s page.', 'auxin-elements' ), |
| 387 | '<a href="'. $welcome_tab_url .'features" title="Version ' . THEME_NAME_I18N . '" >' . THEME_NAME_I18N . ' ', |
| 388 | '</a>', |
| 389 | '<a href="'. admin_url( 'customize.php' ). '?url=' . $welcome_tab_url .'features" title="'. __('Theme Customizer', 'auxin-elements' ) .'" >', |
| 390 | '</a>', |
| 391 | '<a href="'. $welcome_tab_url .'support">', |
| 392 | '</a>', |
| 393 | '<a href="'. $welcome_tab_url .'feedback">', |
| 394 | '</a>' |
| 395 | ); |
| 396 | |
| 397 | return '<span id="footer-thankyou">' . $auxin_text . '</span>'; |
| 398 | } |
| 399 | add_filter( 'admin_footer_text', 'auxin_admin_footer_text' ); |
| 400 | |
| 401 | |
| 402 | |
| 403 | /*-----------------------------------------------------------------------------------*/ |
| 404 | /* Assign menus on start or after demo import |
| 405 | /*-----------------------------------------------------------------------------------*/ |
| 406 | |
| 407 | /** |
| 408 | * Automatically assigns the appropriate menus to menu locations |
| 409 | * Known Locations: |
| 410 | * - header-primary : There should be a menu with the word "Primary" Or "Mega" in its name |
| 411 | * - header-secondary: There should be a menu with the word "Secondary" in its name |
| 412 | * - footer : There should be a menu with the word "Footer" in its name |
| 413 | * |
| 414 | * @return bool True if at least one menu was assigned, false otherwise |
| 415 | */ |
| 416 | function auxin_assign_default_menus(){ |
| 417 | |
| 418 | $assinged = false; |
| 419 | $locations = get_theme_mod('nav_menu_locations'); |
| 420 | $nav_menus = wp_get_nav_menus(); |
| 421 | |
| 422 | foreach ( $nav_menus as $nav_menu ) { |
| 423 | $menu_name = strtolower( $nav_menu->name ); |
| 424 | |
| 425 | if( empty( $locations['header-secondary'] ) && preg_match( '(secondary)', $menu_name ) ){ |
| 426 | $locations['header-secondary'] = $nav_menu->term_id; |
| 427 | $assinged = true; |
| 428 | } elseif( empty( $locations['header-primary'] ) && preg_match( '(primary|mega|header)', $menu_name ) ){ |
| 429 | $locations['header-primary'] = $nav_menu->term_id; |
| 430 | $assinged = true; |
| 431 | } elseif( empty( $locations['footer'] ) && preg_match( '(footer)', $menu_name ) ){ |
| 432 | $locations['footer'] = $nav_menu->term_id; |
| 433 | $assinged = true; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | set_theme_mod( 'nav_menu_locations', $locations ); |
| 438 | return $assinged; |
| 439 | } |
| 440 | |
| 441 | add_action( 'after_switch_theme', 'auxin_assign_default_menus' ); // triggers when theme will be actived, WP 3.3 |
| 442 | add_action( 'import_end', 'auxin_assign_default_menus' ); // triggers when the theme data was imported |
| 443 | |
| 444 | /*-----------------------------------------------------------------------------------*/ |
| 445 | /* Remove any script tag fromt custom js (if user used them in the script content) |
| 446 | /*-----------------------------------------------------------------------------------*/ |
| 447 | |
| 448 | /** |
| 449 | * Strip <script> tags |
| 450 | * |
| 451 | * @param string $js_string The custom js string |
| 452 | * @return string The sanitized custom js code |
| 453 | */ |
| 454 | function auxels_strip_script_tags_from_custom_js( $js_string ){ |
| 455 | if ( false !== stripos( $js_string, '</script>' ) ) { |
| 456 | $js_string = str_replace( array( "<script>", "</script>" ), array('', ''), $js_string ); |
| 457 | } |
| 458 | return $js_string; |
| 459 | } |
| 460 | add_filter( 'auxin_custom_js_string', 'auxels_strip_script_tags_from_custom_js' ); |
| 461 | |
| 462 | /*-----------------------------------------------------------------------------------*/ |
| 463 | /* Remove any style tag fromt custom css (if user used them in the style content) |
| 464 | /*-----------------------------------------------------------------------------------*/ |
| 465 | |
| 466 | /** |
| 467 | * Strip <style> tags |
| 468 | * |
| 469 | * @param string $css_string The custom css string |
| 470 | * @return string The sanitized custom css code |
| 471 | */ |
| 472 | function auxels_strip_style_tags_from_custom_css( $css_string ){ |
| 473 | if ( false !== stripos( $css_string, '</style>' ) ) { |
| 474 | $css_string = str_replace( array( "<style>", "</style>" ), array('', ''), $css_string ); |
| 475 | } |
| 476 | return $css_string; |
| 477 | } |
| 478 | add_filter( 'auxin_custom_css_string', 'auxels_strip_style_tags_from_custom_css' ); |
| 479 | |
| 480 | /*-----------------------------------------------------------------------------------*/ |
| 481 |