public static function resolveWordPressPostToModel(\WP_Post $post) { /** @var PostTypeManager $postTypes */ $postTypes = app('posts.types'); if ($class = $postTypes->get($post->post_type)) { return with(new $class())->newInstance($post->to_array()); } return false; }
/** * {@inheritdoc} */ public function normalize($blogId, \WP_Post $post) { $out = $post->to_array(); unset($out['post_category'], $out['tags_input']); $out['terms'] = $this->buildTerms($post); if (!empty($post->post_author)) { $out['post_author'] = $this->buildAuthor($post); } return $out; }
private function _handleDataAndSettingsPage() { if ($_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'))) { if ($this->_chart->post_status == 'auto-draft') { $this->_chart->post_status = 'publish'; wp_update_post($this->_chart->to_array()); } update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST); $render = new Visualizer_Render_Page_Send(); $render->text = sprintf('[visualizer id="%d"]', $this->_chart->ID); wp_iframe(array($render, 'render')); return; } $data = $this->_getChartArray(); $sidebar = ''; $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst($data['type']); if (class_exists($sidebar_class, true)) { $sidebar = new $sidebar_class($data['settings']); $sidebar->__series = $data['series']; $sidebar->__data = $data['data']; } else { $sidebar = apply_filters("visualizer_pro_chart_type_sidebar", '', $data); if ($sidebar != '') { $sidebar->__series = $data['series']; $sidebar->__data = $data['data']; } } unset($data['settings']['width'], $data['settings']['height']); wp_enqueue_style('visualizer-frame'); wp_enqueue_style('wp-color-picker'); wp_enqueue_style('visualizer-frame'); wp_enqueue_script('visualizer-preview'); wp_enqueue_script('visualizer-render'); wp_localize_script('visualizer-render', 'visualizer', array('l10n' => array('remotecsv_prompt' => esc_html__('Please, enter the URL of CSV file:', Visualizer_Plugin::NAME), 'invalid_source' => esc_html__('You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME)), 'charts' => array('canvas' => $data))); $render = new Visualizer_Render_Page_Data(); $render->chart = $this->_chart; $render->type = $data['type']; $render->sidebar = $sidebar; if (filter_input(INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN)) { $render->button = filter_input(INPUT_GET, 'action') == Visualizer_Plugin::ACTION_EDIT_CHART ? esc_html__('Save Chart', Visualizer_Plugin::NAME) : esc_html__('Create Chart', Visualizer_Plugin::NAME); } else { $render->button = esc_attr__('Insert Chart', Visualizer_Plugin::NAME); } if (defined('Visualizer_Pro')) { global $Visualizer_Pro; $Visualizer_Pro->_enqueueScriptsAndStyles($data); } $this->_addAction('admin_head', 'renderFlattrScript'); wp_iframe(array($render, 'render')); }
/** * Handles chart settigns page. * * @since 1.0.0 * * @access private */ private function _handleSettingsPage() { if ($_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'))) { if ($this->_chart->post_status == 'auto-draft') { $this->_chart->post_status = 'publish'; wp_update_post($this->_chart->to_array()); } update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST); $render = new Visualizer_Render_Page_Send(); $render->text = sprintf('[visualizer id="%d"]', $this->_chart->ID); wp_iframe(array($render, 'render')); return; } $data = $this->_getChartArray(); $sidebar = ''; $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst($data['type']); if (class_exists($sidebar_class, true)) { $sidebar = new $sidebar_class($data['settings']); $sidebar->__series = $data['series']; $sidebar->__data = $data['data']; } unset($data['settings']['width'], $data['settings']['height']); wp_enqueue_style('wp-color-picker'); wp_enqueue_style('visualizer-frame'); wp_enqueue_script('visualizer-preview'); wp_localize_script('visualizer-render', 'visualizer', array('charts' => array('canvas' => $data))); $render = new Visualizer_Render_Page_Settings(); $render->sidebar = $sidebar; if (filter_input(INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN)) { $render->button = filter_input(INPUT_GET, 'action') == Visualizer_Plugin::ACTION_EDIT_CHART ? esc_html__('Save Chart', Visualizer_Plugin::NAME) : esc_html__('Create Chart', Visualizer_Plugin::NAME); } else { $render->button = esc_attr__('Insert Chart', Visualizer_Plugin::NAME); } $this->_addAction('admin_head', 'renderFlattrScript'); wp_iframe(array($render, 'render')); }
public function save() { wp_insert_post($this->post->to_array()); }
/** * Insert or update the post. * * @param \WP_Post $post * @return int */ protected final function savePost(\WP_Post $post) { return wp_insert_post($post->to_array()); }