envato_setup_init.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // This is the setup wizard init file.
  3. // This file changes for each one of dtbaker's themes
  4. // This is where I extend the default 'Envato_Theme_Setup_Wizard' class and can do things like remove steps from the setup process.
  5. // This particular init file has a custom "Update" step that is triggered on a theme update. If the setup wizard finds some old shortcodes after a theme update then it will go through the content and replace them. Probably remove this from your end product.
  6. if ( ! defined( 'ABSPATH' ) ) exit;
  7. if ( ! function_exists( 'envato_theme_setup_wizard' ) ) :
  8. function envato_theme_setup_wizard() {
  9. if(class_exists('Envato_Theme_Setup_Wizard')) {
  10. class dtbwp_Envato_Theme_Setup_Wizard extends Envato_Theme_Setup_Wizard {
  11. /**
  12. * Holds the current instance of the theme manager
  13. *
  14. * @since 1.1.3
  15. * @var Envato_Theme_Setup_Wizard
  16. */
  17. private static $instance = null;
  18. /**
  19. * @since 1.1.3
  20. *
  21. * @return Envato_Theme_Setup_Wizard
  22. */
  23. public static function get_instance() {
  24. if ( ! self::$instance ) {
  25. self::$instance = new self;
  26. }
  27. return self::$instance;
  28. }
  29. public function init_actions(){
  30. if ( apply_filters( $this->theme_name . '_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
  31. add_filter( $this->theme_name . '_theme_setup_wizard_content', array(
  32. $this,
  33. 'theme_setup_wizard_content'
  34. ) );
  35. add_filter( $this->theme_name . '_theme_setup_wizard_steps', array(
  36. $this,
  37. 'theme_setup_wizard_steps'
  38. ) );
  39. }
  40. parent::init_actions();
  41. }
  42. public function theme_setup_wizard_steps($steps){
  43. //unset($steps['design']); // this removes the "logo" step
  44. return $steps;
  45. }
  46. public function theme_setup_wizard_content($content){
  47. if($this->is_possible_upgrade()){
  48. array_unshift_assoc($content,'upgrade',array(
  49. 'title' => esc_html__( 'Upgrade', 'taskereasy' ),
  50. 'description' => esc_html__( 'Upgrade Content and Settings', 'taskereasy' ),
  51. 'pending' => esc_html__( 'Pending.', 'taskereasy' ),
  52. 'installing' => esc_html__( 'Installing Updates.', 'taskereasy' ),
  53. 'success' => esc_html__( 'Success.', 'taskereasy' ),
  54. 'install_callback' => array( $this,'_content_install_updates' ),
  55. 'checked' => 1
  56. ));
  57. }
  58. return $content;
  59. }
  60. public function is_possible_upgrade(){
  61. $widget = get_option('widget_text');
  62. if(is_array($widget)) {
  63. foreach($widget as $item){
  64. if(isset($item['dtbwp_widget_bg'])){
  65. return true;
  66. }
  67. }
  68. }
  69. // check if shop page is already installed?
  70. $shoppage = get_page_by_title( 'Shop' );
  71. if ( $shoppage || get_option( 'page_on_front', false ) ) {
  72. return true;
  73. }
  74. return false;
  75. }
  76. public function _content_install_updates(){
  77. // replace old line shortcode with new one.
  78. global $wpdb;
  79. $sql = "UPDATE ".$wpdb->posts." SET post_content = REPLACE ( post_content, 'boutique_line', 'dtbaker_line');";
  80. $wpdb->query($sql);
  81. $sql = "UPDATE ".$wpdb->posts." SET post_content = REPLACE ( post_content, 'boutique_banner', 'dtbaker_banner');";
  82. $wpdb->query($sql);
  83. $sql = "UPDATE ".$wpdb->posts." SET post_content = REPLACE ( post_content, 'boutique_icon', 'dtbaker_icon');";
  84. $wpdb->query($sql);
  85. $sql = "UPDATE ".$wpdb->posts." SET post_content = REPLACE ( post_content, 'google_map', 'dtbaker_google_map');";
  86. $wpdb->query($sql);
  87. $widget = get_option('widget_text');
  88. if(is_array($widget)) {
  89. foreach ( $widget as $key => $val ) {
  90. if ( ! empty( $val['text'] ) ) {
  91. $widget[ $key ]['text'] = str_replace( '[dtbaker_icon icon="truck"]', '<div class="dtbaker-icon-truck"></div>', $val['text'] );
  92. }
  93. }
  94. update_option( 'widget_text', $widget );
  95. }
  96. return true;
  97. }
  98. }
  99. dtbwp_Envato_Theme_Setup_Wizard::get_instance();
  100. }else{
  101. // log error?
  102. }
  103. }
  104. endif;