ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

ContentSetting.php (1279B)


      1 <?php
      2 
      3 namespace Materialis\Customizer\Settings;
      4 
      5 class ContentSetting extends \Materialis\Customizer\BaseSetting
      6 {
      7 
      8     public static $pageIDRegex = '/<!--@@CPPAGEID\[(.*)\]@@-->/s';
      9     
     10     public function update($value)
     11     {
     12         $value = urldecode($value);
     13 
     14         if (is_string($value)) {
     15             $pages_content = json_decode($value, true);
     16         } else {
     17             $pages_content = $value;
     18         }
     19         
     20         foreach ($pages_content as $page_id => $content) {
     21             wp_update_post(array(
     22                 'ID'           => $page_id,
     23                 'post_content' => $content,
     24             ));
     25         }
     26         
     27         parent::update(array());
     28     }
     29     
     30     public function value()
     31     {
     32         if ($this->is_previewed) {
     33             $value = $this->post_value(null);
     34             $value = urldecode($value);
     35             
     36             // json decode for save as draft issue//
     37             try {
     38                 if (is_string($value)) {
     39                     $value = json_decode($value, true);
     40                 }
     41             } catch (\Exception $e) {
     42                 $value = "{}";
     43             }
     44             
     45             return $value;
     46         } else {
     47             return array();
     48         }
     49     }
     50 }