public static function get() { $option = get_option(Skeletons::get('slug')); if ($option instanceof Options) { return apply_filters(Skeletons::get('slug') . '\\get', $option); } return null; }
public static function get($post = null) { if (!($post = self::get_post($post))) { return null; } $meta = apply_filters(Skeletons::get('slug') . '\\get', '_' . Skeletons::get('slug'), $post); $meta = get_post_meta($post->ID, $meta, true); if ($meta instanceof self) { return $meta; } return new static($post); }
public function __toString() { return preg_replace_callback(Options::instance()->pattern, function ($matches) { if ($this->get_partial($key = $this->get_key($matches[1])) && ($partial = get_post($this->get_value($key)))) { if (apply_filters(Skeletons::get('slug') . '\\cache_partials', false)) { return $partial->post_content; } else { return sprintf('[%s %s]', Shortcode::instance(), $partial->ID); } } return $this->get_value($matches[1]); }, $this->file_get_contents($this->skeleton)); }
protected function vars($key) { if (!isset($_REQUEST['post'])) { return ''; } if ($partial = $this->get_partial($key)) { $partials = wp_list_pluck(get_posts(apply_filters(Skeletons::get('slug') . '\\partials', array('post_type' => $partial, 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'asc'))), 'post_title', 'ID'); $partials[0] = __('Select partial', Skeletons::get('textdomain')); $partial = get_post($this->get_value($key)); return sprintf('<a href="#" class="editable" id="%s" data-pk="%s" data-type="select" data-options="%s" data-value="%s">%s</a>', $this->get_key($key), $_REQUEST['post'], str_replace('"', "_quot_", json_encode($partials)), $partial ? $partial->ID : 0, $partial ? $partial->post_title : ''); } return sprintf('<a href="#" class="editable" id="%s" data-pk="%s" data-type="textarea" data-value="%s">%s</a>', $this->get_key($key), $_REQUEST['post'], $this->escape($this->get_value($key)), preg_replace('/\\n+/', '', nl2br($this->escape($this->get_value($key))))); }
public function edit_form_after_title($post) { // TODO global static method to check credentials if (!in_array($post->post_type, Options::instance()->post_types)) { return; } $content = Content::get($post); if (!(bool) $content->skeleton) { return; } remove_post_type_support($post->post_type, 'editor'); echo Skeletons::get_template('editor-template.php', array('id' => Skeletons::apply_filters('template\\editor\\id', Skeletons::get('slug') . '\\content'), 'content' => Skeletons::apply_filters('template\\editor', $content))); }
public static function delete() { $option = delete_option(Skeletons::get('slug')); return apply_filters(Skeletons::get('slug') . '\\delete', $option); }
protected function locate_dir($file) { $directories = apply_filters(Skeletons::get('slug') . '\\directories', array(get_stylesheet_directory() . '/skeletons')); foreach ($directories as $directory) { $directory = trailingslashit($directory); if (is_file($directory . $file)) { return $directory; } } return false; }
public function syntax_highlight() { foreach (array('highlight', 'prettify') as $value) { $this->input('radio', Skeletons::get('slug') . '\\syntax_highlight\\' . $value, Skeletons::get('slug') . '[syntax_highlight]', $value, ucfirst($value), checked(Options::instance()->syntax_highlight, $value, false)); } }
protected function __construct() { $this->shortcode = apply_filters(Skeletons::get('slug') . '\\shortcode', Skeletons::get('slug') . '\\' . $this->shortcode); add_action('init', array($this, 'init')); }
public function save_post($post_id) { $post = get_post($post_id); if (!in_array($post->post_type, Options::instance()->post_types)) { return; } // nonce is set if (!isset($_REQUEST[Skeletons::get('slug')])) { return; } // nonce is valid if (!check_admin_referer(Skeletons::get('slug'), Skeletons::get('slug'))) { return; } // is autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // user can $post_type = get_post_type_object($post->post_type); if (!current_user_can($post_type->cap->edit_post, $post_id)) { return; } // save $meta = '_' . Skeletons::get('slug'); $skeleton = !empty($_REQUEST[$meta]) ? $_REQUEST[$meta] : null; $response = wp_safe_remote_post(admin_url('admin-ajax.php'), array('cookies' => $_COOKIE, 'body' => array('action' => 'skeletons', 'pk' => $post_id, 'name' => 'skeleton', 'value' => $skeleton))); // TODO handled errors // http://wordpress.stackexchange.com/questions/15354/passing-error-warning-messages-from-a-meta-box-to-admin-notices // if ( is_wp_error( $response ) ) { // $error_message = $response->get_error_message(); // echo "Something went wrong: $error_message"; //} }