| @@ -914,8 +914,16 @@ | ||
| 914 | 914 | |
| 915 | 915 | return $meta; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | + public function update_json_meta( $key, $value ) { | |
| 919 | + $this->update_meta( | |
| 920 | + $key, | |
| 921 | + // `wp_slash` in order to avoid the unslashing during the `update_post_meta` | |
| 922 | + wp_slash( wp_json_encode( $value ) ) | |
| 923 | + ); | |
| 924 | + } | |
| 925 | + | |
| 918 | 926 | /** |
| 919 | 927 | * @since 2.0.0 |
| 920 | 928 | * @access public |
| 921 | 929 | * |
| @@ -1561,10 +1569,12 @@ | ||
| 1561 | 1569 | } |
| 1562 | 1570 | } |
| 1563 | 1571 | } |
| 1564 | 1572 | |
| 1565 | - private function process_element_import_export( Controls_Stack $element, $method ) { | |
| 1566 | - $element_data = $element->get_data(); | |
| 1573 | + public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) { | |
| 1574 | + if ( null === $element_data ) { | |
| 1575 | + $element_data = $element->get_data(); | |
| 1576 | + } | |
| 1567 | 1577 | |
| 1568 | 1578 | if ( method_exists( $element, $method ) ) { |
| 1569 | 1579 | // TODO: Use the internal element data without parameters. |
| 1570 | 1580 | $element_data = $element->{$method}( $element_data ); |
| @@ -1577,10 +1587,17 @@ | ||
| 1577 | 1587 | if ( ! $control_class ) { |
| 1578 | 1588 | return $element_data; |
| 1579 | 1589 | } |
| 1580 | 1590 | |
| 1581 | - if ( method_exists( $control_class, $method ) ) { | |
| 1582 | - $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control ); | |
| 1591 | + // Do not add default value to the final settings, if there is no value at the | |
| 1592 | + // data before the methods `on_import` or `on_export` called. | |
| 1593 | + $has_value = isset( $element_data['settings'][ $control['name'] ] ); | |
| 1594 | + | |
| 1595 | + if ( $has_value && method_exists( $control_class, $method ) ) { | |
| 1596 | + $element_data['settings'][ $control['name'] ] = $control_class->{$method}( | |
| 1597 | + $element_data['settings'][ $control['name'] ], | |
| 1598 | + $control | |
| 1599 | + ); | |
| 1583 | 1600 | } |
| 1584 | 1601 | |
| 1585 | 1602 | // On Export, check if the control has an argument 'export' => false. |
| 1586 | 1603 | if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) { |