ReduxFramework_extension_import_export

Main ReduxFramework import_export extension class.

Defined (1)

The class is defined in the following location(s).

/library/admin/redux-framework/inc/extensions/import_export/extension_import_export.php  
  1. class ReduxFramework_extension_import_export { 
  2.  
  3. // Protected vars 
  4. protected $parent; 
  5. public $extension_url; 
  6. public $extension_dir; 
  7. public static $theInstance; 
  8. public static $version = "4.0"; 
  9. public $is_field = false; 
  10.  
  11. /** 
  12. * Class Constructor. Defines the args for the extions class 
  13. * @since 1.0.0 
  14. * @access public 
  15. * @param array $sections Panel sections. 
  16. * @param array $args Class constructor arguments. 
  17. * @param array $extra_tabs Extra panel tabs. 
  18. * @return void 
  19. */ 
  20. public function __construct( $parent ) { 
  21.  
  22. $this->parent = $parent; 
  23. if ( empty( $this->extension_dir ) ) { 
  24. //$this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) ); 
  25. $this->field_name = 'import_export'; 
  26.  
  27. self::$theInstance = $this; 
  28.  
  29. add_action( "wp_ajax_redux_link_options-" . $this->parent->args['opt_name'], array( 
  30. $this,  
  31. "link_options" 
  32. ) ); 
  33. add_action( "wp_ajax_nopriv_redux_link_options-" . $this->parent->args['opt_name'], array( 
  34. $this,  
  35. "link_options" 
  36. ) ); 
  37.  
  38. add_action( "wp_ajax_redux_download_options-" . $this->parent->args['opt_name'], array( 
  39. $this,  
  40. "download_options" 
  41. ) ); 
  42. add_action( "wp_ajax_nopriv_redux_download_options-" . $this->parent->args['opt_name'], array( 
  43. $this,  
  44. "download_options" 
  45. ) ); 
  46.  
  47. do_action( "redux/options/{$this->parent->args['opt_name']}/import", array( $this, 'remove_cookie' ) ); 
  48.  
  49. $this->is_field = Redux_Helpers::isFieldInUse( $parent, 'import_export' ); 
  50.  
  51. if ( ! $this->is_field && $this->parent->args['show_import_export'] ) { 
  52. $this->add_section(); 
  53.  
  54. add_filter( 'redux/' . $this->parent->args['opt_name'] . '/field/class/' . $this->field_name, array( 
  55. &$this,  
  56. 'overload_field_path' 
  57. ) ); // Adds the local field 
  58.  
  59. add_filter( 'upload_mimes', array( 
  60. $this,  
  61. 'custom_upload_mimes' 
  62. ) ); 
  63.  
  64.  
  65. /** 
  66. * Adds the appropriate mime types to WordPress 
  67. * @param array $existing_mimes 
  68. * @return array 
  69. */ 
  70. function custom_upload_mimes( $existing_mimes = array() ) { 
  71. $existing_mimes['redux'] = 'application/redux'; 
  72.  
  73. return $existing_mimes; 
  74.  
  75. public function add_section() { 
  76. $this->parent->sections[] = array( 
  77. 'id' => 'import/export',  
  78. 'title' => __( 'Import / Export', 'evolve' ),  
  79. 'heading' => '',  
  80. 'icon' => 'el el-refresh',  
  81. 'customizer' => false,  
  82. 'fields' => array( 
  83. array( 
  84. 'id' => 'redux_import_export',  
  85. 'type' => 'import_export',  
  86. //'class' => 'redux-field-init redux_remove_th',  
  87. //'title' => '',  
  88. 'full_width' => true,  
  89. ),  
  90. ); 
  91.  
  92. function link_options() { 
  93. if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) { 
  94. wp_die( 'Invalid Secret for options use' ); 
  95. exit; 
  96.  
  97. $var = $this->parent->options; 
  98. $var['redux-backup'] = '1'; 
  99. if ( isset( $var['REDUX_imported'] ) ) { 
  100. unset( $var['REDUX_imported'] ); 
  101.  
  102. echo json_encode( $var ); 
  103.  
  104. die(); 
  105.  
  106. public function download_options() { 
  107. if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) { 
  108. wp_die( 'Invalid Secret for options use' ); 
  109. exit; 
  110.  
  111. $this->parent->get_options(); 
  112. $backup_options = $this->parent->options; 
  113. $backup_options['redux-backup'] = '1'; 
  114. if ( isset( $backup_options['REDUX_imported'] ) ) { 
  115. unset( $backup_options['REDUX_imported'] ); 
  116.  
  117. // No need to escape this, as it's been properly escaped previously and through json_encode 
  118. $content = json_encode( $backup_options ); 
  119.  
  120. if ( isset( $_GET['action'] ) && $_GET['action'] == 'redux_download_options-' . $this->parent->args['opt_name'] ) { 
  121. header( 'Content-Description: File Transfer' ); 
  122. header( 'Content-type: application/txt' ); 
  123. header( 'Content-Disposition: attachment; filename="redux_options_' . $this->parent->args['opt_name'] . '_backup_' . date( 'd-m-Y' ) . '.json"' ); 
  124. header( 'Content-Transfer-Encoding: binary' ); 
  125. header( 'Expires: 0' ); 
  126. header( 'Cache-Control: must-revalidate' ); 
  127. header( 'Pragma: public' ); 
  128.  
  129. echo $content; 
  130. exit; 
  131. } else { 
  132. header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
  133. header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); 
  134. header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); 
  135. header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 
  136. header( 'Cache-Control: post-check=0, pre-check=0', false ); 
  137. header( 'Pragma: no-cache' ); 
  138.  
  139. // Can't include the type. Thanks old Firefox and IE. BAH. 
  140. //header("Content-type: application/json"); 
  141. echo $content; 
  142. exit; 
  143.  
  144. // Forces the use of the embeded field path vs what the core typically would use 
  145. public function overload_field_path( $field ) { 
  146. return dirname( __FILE__ ) . '/' . $this->field_name . '/field_' . $this->field_name . '.php'; 
  147.  
  148. public function remove_cookie() { 
  149. // Remove the import/export tab cookie. 
  150. if ( $_COOKIE['redux_current_tab'] == 'import_export_default' ) { 
  151. setcookie( 'redux_current_tab', '', 1, '/' ); 
  152. $_COOKIE['redux_current_tab'] = 1; 
  153.