* @copyright Copyright (c) 2013-2015, Nicolas GUILLAUME * @link http://presscustomizr.com/customizr * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ if ( ! class_exists( 'TC_admin_init' ) ) : class TC_admin_init { static $instance; function __construct () { self::$instance =& $this; //enqueue additional styling for admin screens add_action( 'admin_init' , array( $this , 'tc_admin_style' ) ); //Load the editor-style specific (post formats and RTL), the active skin, the user style.css //add user defined fonts in the editor style (@see the query args add_editor_style below) add_action( 'after_setup_theme' , array( $this, 'tc_add_editor_style') ); add_filter( 'tiny_mce_before_init' , array( $this, 'tc_user_defined_tinymce_css') ); //refresh the post / CPT / page thumbnail on save. Since v3.3.2. add_action ( 'save_post' , array( $this , 'tc_refresh_thumbnail') , 10, 2); //refresh the posts slider transient on save_post. Since v3.4.9. add_action ( 'save_post' , array( $this , 'tc_refresh_posts_slider'), 20, 2 ); //refresh the posts slider transient on permanent post/attachment deletion. Since v3.4.9. add_action ( 'deleted_post' , array( $this , 'tc_refresh_posts_slider') ); //refresh the terms array (categories/tags pickers options) on term deletion add_action ( 'delete_term' , array( $this, 'tc_refresh_terms_pickers_options_cb'), 10, 3 ); //UPDATE NOTICE add_action( 'admin_notices' , array( $this, 'tc_may_be_display_update_notice') ); //always add the ajax action add_action( 'wp_ajax_dismiss_customizr_update_notice' , array( $this , 'tc_dismiss_update_notice_action' ) ); add_action( 'admin_footer' , array( $this , 'tc_write_ajax_dismis_script' ) ); /* beautify admin notice text using some defaults the_content filter callbacks */ foreach ( array( 'wptexturize', 'convert_smilies', 'wpautop') as $callback ) add_filter( 'tc_update_notice', $callback ); } /* * @return void * updates the tc-thumb-fld post meta with the relevant thumb id and type * @package Customizr * @since Customizr 3.3.2 */ function tc_refresh_thumbnail( $post_id, $post ) { // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) || ( ! empty($post) && 'auto-draft' == $post->post_status ) ) return; if ( ! class_exists( 'TC_post_thumbnails' ) ) TC___::$instance -> tc__( array('content' => array( array('inc/parts', 'post_thumbnails') ) ), true ); TC_post_thumbnails::$instance -> tc_set_thumb_info( $post_id ); } /* * @return void * updates the posts slider transient * @package Customizr * @since Customizr 3.4.9 */ function tc_refresh_posts_slider( $post_id, $post = array() ) { // no need to build up/refresh the transient it we don't use the posts slider // since we always delete the transient when entering the preview. if ( 'tc_posts_slider' != TC_utils::$inst->tc_opt( 'tc_front_slider' ) || ! apply_filters('tc_posts_slider_use_transient' , true ) ) return; if ( wp_is_post_revision( $post_id ) || ( ! empty($post) && 'auto-draft' == $post->post_status ) ) return; if ( ! class_exists( 'TC_post_thumbnails' ) ) TC___::$instance -> tc__( array('content' => array( array('inc/parts', 'post_thumbnails') ) ), true ); if ( ! class_exists( 'TC_slider' ) ) TC___::$instance -> tc__( array('content' => array( array('inc/parts', 'slider') ) ), true ); TC_slider::$instance -> tc_cache_posts_slider(); } /* * @return void * updates the term pickers related options * @package Customizr * @since Customizr 3.4.10 */ function tc_refresh_terms_picker_options_cb( $term, $tt_id, $taxonomy ) { switch ( $taxonomy ) { //delete categories based options case 'category': $this -> tc_refresh_term_picker_options( $term, $option_name = 'tc_blog_restrict_by_cat' ); break; } } function tc_refresh_term_picker_options( $term, $option_name, $option_group = null ) { //home/blog posts category picker $_option = TC_utils::$inst -> tc_opt( $option_name, $option_group, $use_default = false ); if ( is_array( $_option ) && ! empty( $_option ) && in_array( $term, $_option ) ) //update the option TC_utils::$inst -> tc_set_option( $option_name, array_diff( $_option, (array)$term ) ); //alternative, cycle throughout the cats and keep just the existent ones /*if ( is_array( $blog_cats ) && ! empty( $blog_cats ) ) { //update the option TC_utils::$inst -> tc_set_option( 'tc_blog_restrict_by_cat', array_filter( $blog_cats, array(TC_utils::$inst, 'tc_category_id_exists' ) ) ); }*/ } /* * @return css string * * @package Customizr * @since Customizr 3.2.10 */ function tc_maybe_add_gfonts_to_editor() { $_font_pair = esc_attr( TC_utils::$inst->tc_opt('tc_fonts') ); $_all_font_pairs = TC_init::$instance -> font_pairs; if ( false === strpos($_font_pair,'_g_') ) return; //Commas in a URL need to be encoded before the string can be passed to add_editor_style. return array( str_replace( ',', '%2C', sprintf( '//fonts.googleapis.com/css?family=%s', TC_utils::$inst -> tc_get_font( 'single' , $_font_pair ) ) ) ); } /** * enqueue additional styling for admin screens * @package Customizr * @since Customizr 3.0.4 */ function tc_admin_style() { wp_enqueue_style( 'tc-admincss', sprintf('%1$sinc/admin/css/tc_admin%2$s.css' , TC_BASE_URL, ( defined('WP_DEBUG') && true === WP_DEBUG ) ? '' : '.min' ), array(), CUSTOMIZR_VER ); } /** * Extract changelog of latest version from readme.txt file * @package Customizr * @since Customizr 3.0.5 */ function tc_extract_changelog() { if( ! file_exists(TC_BASE."readme.txt") ) { return; } if( ! is_readable(TC_BASE."readme.txt") ) { echo '
The changelog in readme.txt is not readable.
'; return; } $stylelines = explode("\n", implode('', file(TC_BASE."readme.txt"))); $read = false; $i = 0; foreach ($stylelines as $line) { //echo 'i = '.$i.'|read = '.$read.'pos = '.strpos($line, '= ').'|line :'.$line.'%1$s ( %2$s x ) ', __("I already know what's new thanks !", "customizr" ), __('close' , 'customizr') ); ?>