base.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. *
  4. * @desc registers a theme activation hook
  5. * @param string $code : Code of the theme. This can be the base folder of your theme. Eg if your theme is in folder 'mytheme' then code will be 'mytheme'
  6. * @param callback $function : Function to call when theme gets activated.
  7. */
  8. function vamtam_register_theme_activation_hook( $code, $function ) {
  9. $optionKey = 'theme_is_activated_' . $code;
  10. if ( ! get_option( $optionKey ) ) {
  11. call_user_func( $function );
  12. update_option( $optionKey , 1 );
  13. }
  14. }
  15. // theme activation hook
  16. function vamtam_theme_activated() {
  17. if ( vamtam_validate_install() ) {
  18. vamtam_register_theme_activation_hook( 'vamtam_' . VAMTAM_THEME_NAME, 'vamtam_theme_activated' );
  19. // disable jetpack likes & comments modules on activation
  20. $jetpack_opt_name = 'jetpack_active_modules';
  21. update_option( $jetpack_opt_name, array_diff( get_option( $jetpack_opt_name, array() ), array( 'likes', 'comments' ) ) );
  22. require_once VAMTAM_DIR . 'classes/plugin-activation.php';
  23. require_once VAMTAM_SAMPLES_DIR . 'dependencies.php';
  24. if ( class_exists( 'TGM_Plugin_Activation' ) ) {
  25. if ( did_action( 'tgmpa_register' ) ) {
  26. vamtam_maybe_redirect_to_tgmpa();
  27. } else {
  28. add_action( 'tgmpa_register', 'vamtam_maybe_redirect_to_tgmpa', 1000, 1 );
  29. }
  30. }
  31. }
  32. }
  33. function vamtam_maybe_redirect_to_tgmpa() {
  34. if ( ! TGM_Plugin_Activation::get_instance()->is_tgmpa_complete() && ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
  35. wp_redirect( TGM_Plugin_Activation::get_instance()->get_tgmpa_url() );
  36. }
  37. }
  38. vamtam_register_theme_activation_hook( 'vamtam_' . VAMTAM_THEME_NAME, 'vamtam_theme_activated' );
  39. add_action( 'admin_init', 'vamtam_validate_install' );
  40. function vamtam_validate_install() {
  41. global $vamtam_errors, $vamtam_validated;
  42. if ( $vamtam_validated )
  43. return;
  44. $vamtam_validated = true;
  45. $vamtam_errors = array();
  46. if ( strpos( str_replace( WP_CONTENT_DIR . '/themes/', '', get_template_directory() ), '/' ) !== false ) {
  47. $vamtam_errors[] = esc_html__( 'The theme must be installed in a directory which is a direct child of wp-content/themes/', 'vamtam-consulting' );
  48. }
  49. if ( ! extension_loaded( 'gd' ) || ! function_exists( 'gd_info' ) ) {
  50. $vamtam_errors[] = esc_html__( "It seems that your server doesn't have the GD graphic library installed. Please contact your hosting provider, they should be able to assist you with this issue", 'vamtam-consulting' );
  51. }
  52. if ( count( $vamtam_errors ) ) {
  53. if ( ! function_exists( 'vamtam_invalid_install' ) ) {
  54. function vamtam_invalid_install() {
  55. global $vamtam_errors;
  56. ?>
  57. <div class="updated fade error" style="background: #FEF2F2; border: 1px solid #DFB8BB; color: #666;"><p>
  58. <?php esc_html_e( 'There were some some errors with your Vamtam theme setup:', 'vamtam-consulting' )?>
  59. <ul>
  60. <?php foreach ( $vamtam_errors as $error ) : ?>
  61. <li><?php echo wp_kses_post( $error ) ?></li>
  62. <?php endforeach ?>
  63. </ul>
  64. </p></div>
  65. <?php
  66. }
  67. add_action( 'admin_notices', 'vamtam_invalid_install' );
  68. }
  69. switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
  70. return false;
  71. }
  72. return true;
  73. }
  74. function vamtam_static( $option ) {
  75. if ( isset( $option['static'] ) && $option['static'] ) {
  76. echo 'static'; }
  77. }
  78. function vamtam_description( $id, $desc ) {
  79. if ( ! empty( $desc ) ) : ?>
  80. <div class="row-desc">
  81. <a href="#" class="va-icon va-icon-info desc-handle"></a>
  82. <div>
  83. <section class="content"><?php echo wp_kses_post( $desc ) ?></section>
  84. <footer><a href="<?php echo esc_url( 'http://support.vamtam.com' ) ?>" title="<?php esc_attr_e( 'Read more on our Help Desk', 'vamtam-consulting' ) ?>" target="_blank"><?php esc_html_e( 'Read more on our Help Desk', 'vamtam-consulting' ) ?></a></footer>
  85. </div>
  86. </div>
  87. <?php endif;
  88. }
  89. function vamtam_compile_less_ajax() {
  90. if ( ! wp_verify_nonce( $_POST['_nonce'], 'vamtam-compile-less' ) ) {
  91. exit;
  92. }
  93. $error = VamtamLessBridge::basic_compile( $_POST['input'], $_POST['output'] );
  94. if ( $error ) {
  95. echo json_encode( array(
  96. 'status' => 'error',
  97. 'message' => $error,
  98. 'memory' => memory_get_peak_usage() / 1024 / 1024,
  99. ) );
  100. } else {
  101. echo json_encode( array(
  102. 'status' => 'ok',
  103. 'memory' => memory_get_peak_usage() / 1024 / 1024,
  104. ) );
  105. }
  106. exit;
  107. }
  108. add_action( 'wp_ajax_vamtam-compile-less', 'vamtam_compile_less_ajax' );