public static function get()
 {
     $option = get_option(Skeletons::get('slug'));
     if ($option instanceof Options) {
         return apply_filters(Skeletons::get('slug') . '\\get', $option);
     }
     return null;
 }
示例#2
0
 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)))));
 }
示例#5
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 static function delete()
 {
     $option = delete_option(Skeletons::get('slug'));
     return apply_filters(Skeletons::get('slug') . '\\delete', $option);
 }
示例#7
0
 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'));
 }
示例#10
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";
     //}
 }
示例#11
0
	Clearcode Skeletons is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	Clearcode Skeletons is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Clearcode Skeletons; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
namespace Clearcode\Skeletons;

use Clearcode\Skeletons;
if (!defined('ABSPATH')) {
    exit;
}
if (!function_exists('get_plugin_data')) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
foreach (array('singleton', 'plugin') as $name) {
    require_once plugin_dir_path(__FILE__) . sprintf('includes/class-%s.php', $name);
}
spl_autoload_register(__NAMESPACE__ . '\\Plugin::autoload');
if (!has_action(__NAMESPACE__)) {
    do_action(__NAMESPACE__, Skeletons::instance());
}