예제 #1
0
/**
 * @param $content
 * @param bool $entities
 * @param bool $p
 * @param bool $br
 *
 * @return mixed|string
 */
function cl_tpf($content, $entities = true, $p = true, $br = false)
{
    require 'vendor/remotetypograf.php';
    $typograf = new RemoteTypograf(get_bloginfo('charset'));
    if ($entities) {
        $typograf->htmlEntities();
    } else {
        $typograf->noEntities();
    }
    $typograf->br($br);
    $typograf->p($p);
    $result = $typograf->processText(stripcslashes($content));
    return $result;
}
예제 #2
0
 /**
  * Save hook, typography text
  *
  * @param $post_ID int
  */
 function save_post_process($post_ID)
 {
     global $post;
     if (!$post) {
         return;
     }
     $tp = (bool) get_option('cl_tpf_' . $post->post_type);
     if (!$tp) {
         return;
     }
     if (wp_is_post_revision($post_ID)) {
         return;
     }
     if (!isset($_POST['cl_tpf_use'])) {
         update_post_meta($post_ID, 'cl_tpf_disable', 'on');
         return;
     } else {
         delete_post_meta($post_ID, 'cl_tpf_disable');
     }
     $post_title = $_POST['post_title'];
     $post_excerpt = $_POST['post_excerpt'];
     $post_content = $_POST['post_content'];
     $big_length = 32768;
     $typograf = new RemoteTypograf(get_bloginfo('charset'));
     $typograf->noEntities();
     $typograf->br(false);
     $typograf->p(false);
     $title = !empty($post_title) && mb_strlen($post_title) < $big_length ? $typograf->processText(strip_tags($post_title)) : '';
     $excerpt = !empty($post_excerpt) && mb_strlen($post_excerpt) < $big_length ? $typograf->processText(strip_tags($post_excerpt)) : '';
     $typograf->htmlEntities();
     $typograf->br(false);
     $typograf->p(true);
     $content = !empty($post_content) && mb_strlen($post_content) < $big_length ? $typograf->processText($post_content) : '';
     remove_action('save_post', array($this, 'save_post_process'));
     wp_update_post(array('ID' => $post_ID, 'post_title' => $title, 'post_excerpt' => $excerpt, 'post_content' => $content));
     add_action('save_post', array($this, 'save_post_process'));
 }