Esempio n. 1
0
 public static function get_post($post = null)
 {
     if (null === ($post = get_post($post))) {
         return null;
     }
     if (!in_array($post->post_type, Options::instance()->post_types)) {
         return null;
     }
     return $post;
 }
Esempio n. 2
0
 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));
 }
Esempio n. 3
0
 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 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));
     }
 }
Esempio n. 5
0
 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";
     //}
 }
Esempio n. 6
0
 public function __toString()
 {
     return preg_replace_callback(Options::instance()->pattern, function ($matches) {
         return $this->vars($matches[1]);
     }, $this->escape($this->file_get_contents($this->skeleton)));
 }