post_status ) )
return;
//if czr4
if ( czr_fn_is_ms() ) {
if ( function_exists( 'czr_fn_set_thumb_info' ) )
czr_fn_set_thumb_info( $post_id );
}
else {
if ( ! class_exists( 'CZR_post_thumbnails' ) || ! is_object(CZR_post_thumbnails::$instance) ) {
CZR___::$instance -> czr_fn_req_once( 'inc/czr-front-ccat.php' );
new CZR_post_thumbnails();
}
CZR_post_thumbnails::$instance -> czr_fn_set_thumb_info( $post_id );
}
}
/*
* hook : 'delete_term'
* @return void
* updates the term pickers related options
* @package Customizr
* @since Customizr 3.4.10
*/
function czr_fn_refresh_terms_pickers_options_cb( $term, $tt_id, $taxonomy ) {
switch ( $taxonomy ) {
//delete categories based options
case 'category':
$this -> czr_fn_refresh_term_picker_options( $term, $option_name = 'tc_blog_restrict_by_cat' );
break;
}
}
function czr_fn_refresh_term_picker_options( $term, $option_name, $option_group = null ) {
// czr_fn_get_opt and czr_fn_set_option in core/utils/ class-fire-utils_option
//home/blog posts category picker
$_option = czr_fn_opt( $option_name, $option_group, $use_default = false );
if ( is_array( $_option ) && ! empty( $_option ) && in_array( $term, $_option ) )
//update the option
czr_fn_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
czr_fn_set_option( 'tc_blog_restrict_by_cat', array_filter( $blog_cats, 'czr_fn_category_id_exists' ) );
}*/
}
/*
* hook : 'czr_add_custom_fonts_to_editor'
* @return css string
*
* @package Customizr
* @since Customizr 3.2.10
*/
function czr_fn_maybe_add_gfonts_to_editor() {
$_font_pair = esc_attr( czr_fn_opt('tc_fonts') );
$_all_font_pairs = CZR___::$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.
//czr_fn_get_font defined in core/utils/class-fire-utils
return array(
str_replace(
',',
'%2C',
sprintf( '//fonts.googleapis.com/css?family=%s', czr_fn_get_font( 'single' , $_font_pair ) )
)
);
}
/**
* hook : 'admin_init'
* enqueue additional styling for admin screens
* @package Customizr
* @since Customizr 3.0.4
*/
function czr_fn_admin_style() {
wp_enqueue_style(
'tc-admincss',
sprintf('%1$sback/css/tc_admin%2$s.css' ,
CZR_BASE_URL . CZR_ASSETS_PREFIX,
( defined('WP_DEBUG') && true === WP_DEBUG ) ? '' : '.min'
),
array(),
( defined('WP_DEBUG') && true === WP_DEBUG ) ? CUSTOMIZR_VER . time() : CUSTOMIZR_VER
);
}
/**
* Extract changelog of latest version from readme.txt file
* @package Customizr
* @since Customizr 3.0.5
*/
function czr_fn_extract_changelog() {
if( ! file_exists(CZR_BASE."readme.txt") ) {
return;
}
if( ! is_readable(CZR_BASE."readme.txt") ) {
echo '
The changelog in readme.txt is not readable.
';
return;
}
$stylelines = explode("\n", implode('', file(CZR_BASE."readme.txt")));
$read = false;
$i = 0;
foreach ($stylelines as $line) {
//echo 'i = '.$i.'|read = '.$read.'pos = '.strpos($line, '= ').'|line :'.$line.' ';
//we stop reading if we reach the next version change
if ($i == 1 && strpos($line, '= ') === 0 ) {
$read = false;
$i = 0;
}
//we write the line if between current and previous version
if ($read) {
echo $line.' ';
}
//we skip all lines before the current version changelog
if ($line != strpos($line, '= '.CUSTOMIZR_VER)) {
if ($i == 0) {
$read = false;
}
}
//we begin to read after current version title
else {
$read = true;
$i = 1;
}
}
}
/**
* Customizr styles the visual editor to resemble the theme style,
* Loads the editor-style specific (post formats and RTL), the active skin, the user style.css, the user_defined fonts
* @package Customizr
* @since Customizr 3.2.11
*
*/
function czr_fn_add_editor_style() {
//array_filter to remove empty array items is not needed as wp function get_editor_stylesheets() (since WP 4.0)
//will do that for us
//we need only the relative path, otherwise get_editor_stylesheets() will treat this as external CSS
//which means:
//a) child-themes cannot override it
//b) no check on the file existence will be made (producing the rtl error, for instance : https://github.com/presscustomizr/customizr/issues/926)
//as of v4.0.10 the editor-style.css is the classic editor style for the Customizr classic style
//4.1.23 block editor style introduced for the Customizr modern style only
//as of 4.1.38 block editor style introduced for the Customizr modern style too
$_style_suffix = CZR_DEBUG_MODE || CZR_DEV_MODE ? '.css' : '.min.css' ;
$_stylesheets = czr_fn_is_ms() ? array( CZR_ASSETS_PREFIX . 'back/css/block-editor-style' . $_style_suffix ) : array( CZR_ASSETS_PREFIX . 'back/css/editor-style' . $_style_suffix, CZR_ASSETS_PREFIX . 'back/css/block-editor-style-cs' . $_style_suffix );
$_stylesheets[] = 'style.css';
if ( ! czr_fn_is_ms() ) {
$_stylesheets[] = 'inc/assets/css/' . esc_attr( czr_fn_opt( 'tc_skin' ) );
}
if ( apply_filters( 'czr_add_custom_fonts_to_editor' , false != $this -> czr_fn_maybe_add_gfonts_to_editor() ) )
$_stylesheets = array_merge( $_stylesheets , $this -> czr_fn_maybe_add_gfonts_to_editor() );
add_editor_style( $_stylesheets );
}
/**
* Extend TinyMCE config with a setup function.
* See http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit
* http://wordpress.stackexchange.com/questions/120831/how-to-add-custom-css-theme-option-to-tinymce
* @package Customizr
* @since Customizr 3.2.11
*
*/
function czr_fn_user_defined_tinymce_css( $init ) {
if ( ! apply_filters( 'czr_add_custom_fonts_to_editor' , true ) )
return $init;
if ( 'tinymce' != wp_default_editor() )
return $init;
$_css = '';
//maybe add rtl class
$_mce_body_context = is_rtl() ? 'mce-content-body.rtl' : 'mce-content-body';
//if modern
if ( czr_fn_is_ms() ) {
//some plugins fire tiny mce editor in the customizer
//in this case, the CZR_resources_fonts class has to be loaded
if ( ! class_exists('CZR_resources_fonts') || ! is_object(CZR_resources_fonts::$instance) )
CZR() -> czr_fn_load( array('fire' => array( array('core' , 'resources_fonts') ) ), true );
if ( class_exists('CZR_resources_fonts') && is_object(CZR_resources_fonts::$instance) ) {
//fonts
$_css .= CZR_resources_fonts::$instance -> czr_fn_write_fonts_inline_css( '', $_mce_body_context );
}
//skin
//some plugins fire tiny mce editor in the customizer
//in this case, the CZR_resources_styles class has to be loaded
if ( ! class_exists('CZR_resources_styles') || ! is_object(CZR_resources_styles::$instance) )
CZR() -> czr_fn_load( array('fire' => array( array('core' , 'resources_styles') ) ), true );
if ( class_exists('CZR_resources_styles') && is_object(CZR_resources_styles::$instance) ) {
//dynamic skin
$_css .= CZR_resources_styles::$instance -> czr_fn_maybe_write_skin_inline_css( '' );
}
}
//classic
else {
//some plugins fire tiny mce editor in the customizer
//in this case, the CZR_resource class has to be loaded
if ( ! class_exists('CZR_resources') || ! is_object(CZR_resources::$instance) ) {
CZR___::$instance -> czr_fn_req_once( 'inc/czr-init-ccat.php' );
new CZR_resources();
}
//fonts
$_css = CZR_resources::$instance -> czr_fn_write_fonts_inline_css( '', $_mce_body_context );
}
if ( $_css )
$init['content_style'] = trim(preg_replace('/\s+/', ' ', $_css ) );
return $init;
}
/**********************************************************************************
* UPDATE NOTICE
* User gets notified when the version stores in the db option 'last_update_notice'
* is < current version of the theme (CUSTOMIZR_VER)
* User can dismiss the notice and the option get updated by ajax to the current version
* The notice will be displayed a maximum of 5 times and will be automatically dismissed until the next update.
* => users won't be notified again until the next update.
**********************************************************************************/
/**
* hook : admin_notices
*/
function czr_fn_may_be_display_update_notice() {
//don't display update notification for a list of versions
//typically useful when several versions are released in a short time interval
//to avoid hammering the wp admin dashboard with a new admin notice each time
if ( ( defined('DISPLAY_UPDATE_NOTIFICATION') && ! DISPLAY_UPDATE_NOTIFICATION ) || ( defined('DISPLAY_PRO_UPDATE_NOTIFICATION') && ! DISPLAY_PRO_UPDATE_NOTIFICATION ) )
return;
$opt_name = CZR_IS_PRO ? 'last_update_notice_pro' : 'last_update_notice';
$last_update_notice_values = czr_fn_opt($opt_name);
$show_new_notice = false;
$display_ct = 50;
if ( ! $last_update_notice_values || ! is_array($last_update_notice_values) ) {
//first time user of the theme, the option does not exist
// 1) initialize it => set it to the current Customizr version, displayed 0 times.
// 2) update in db
$last_update_notice_values = array( "version" => CUSTOMIZR_VER, "display_count" => 0 );
czr_fn_set_option( $opt_name, $last_update_notice_values );
//already user of the theme ?
if ( czr_fn_user_started_before_version( CUSTOMIZR_VER, CUSTOMIZR_VER ) )
$show_new_notice = true;
}
$_db_version = $last_update_notice_values["version"];
$_db_displayed_count = $last_update_notice_values["display_count"];
// user who just upgraded the theme will be notified until he clicks on the dismiss link
// when clicking on the dismiss link OR when the notice has been displayed n times.
// - version will be set to CUSTOMIZR_VER
// - display_count reset to 0
if ( version_compare( CUSTOMIZR_VER, $_db_version , '>' ) ) {
//CASE 1 : displayed less than n times
if ( $_db_displayed_count < $display_ct ) {
$show_new_notice = true;
//increments the counter
(int) $_db_displayed_count++;
$last_update_notice_values["display_count"] = $_db_displayed_count;
//updates the option val with the new count
czr_fn_set_option( $opt_name, $last_update_notice_values );
}
//CASE 2 : displayed n times => automatic dismiss
else {
//reset option value with new version and counter to 0
$new_val = array( "version" => CUSTOMIZR_VER, "display_count" => 0 );
czr_fn_set_option( $opt_name, $new_val );
}//end else
}//end if
if ( ! $show_new_notice )
return;
// prefixed CZR_Plugin_Activation because of the possible issue : https://github.com/presscustomizr/customizr/issues/1603
if ( ! czr_fn_is_plugin_active('nimble-builder/nimble-builder.php') && class_exists('CZR_Plugin_Activation') && ! CZR_Plugin_Activation::get_instance()->czr_fn_is_notice_dismissed() )
return;
ob_start();
?>
%1$s %2$s %3$s %4$s :D',
__( "Good, you've recently upgraded to", "customizr"),
CZR_IS_PRO ? 'Customizr Pro' : 'Customizr',
__( "version", "customizr"),
CUSTOMIZR_VER
)
);
?>
%1$s %3$s »%4$s',
__( "We'd like to introduce the new features we've been working on.", "customizr"),
CZR_WEBSITE . "category/customizr-releases/",
__( "Read the latest release notes" , "customizr" ),
! CZR_IS_PRO ? sprintf( '
sets the last_update_notice to the current Customizr version when user click on dismiss notice link
*/
function czr_fn_dismiss_update_notice_action() {
check_ajax_referer( 'dismiss-update-notice-nonce', 'dismissUpdateNoticeNonce' );
$opt_name = CZR_IS_PRO ? 'last_update_notice_pro' : 'last_update_notice';
//reset option value with new version and counter to 0
$new_val = array( "version" => CUSTOMIZR_VER, "display_count" => 0 );
czr_fn_set_option( $opt_name, $new_val );
wp_die();
}
/**
* hook : admin_footer
*/
function czr_fn_write_ajax_dismis_script() {
?>
support_url = CZR_IS_PRO ? esc_url( sprintf('%ssupport' , CZR_WEBSITE ) ) : esc_url('wordpress.org/support/theme/customizr');
//fix #wpfooter absolute positioning in the welcome and about pages
add_action( 'admin_print_styles' , array( $this, 'czr_fn_fix_wp_footer_link_style') );
//knowledgebase
if ( CZR_IS_PRO ) {
add_action( 'current_screen' , array( $this , 'czr_schedule_welcome_page_actions') );
}
}
/**
* Add fallback admin page.
* @package Customizr
* @since Customizr 1.1
*/
function czr_fn_add_welcome_page() {
$_name = __( 'About Customizr' , 'customizr' );
$_name = CZR_IS_PRO ? sprintf( '%s Pro', $_name ) : $_name;
$theme_page = add_theme_page(
$_name, // Name of page
$_name, // Label in menu
'edit_theme_options' , // Capability required
'welcome.php' , // Menu slug, used to uniquely identify the page
array( $this , 'czr_fn_welcome_panel' ) //function to be called to output the content of this page
);
}
/**
* Render welcome admin page.
* @package Customizr
* @since Customizr 3.0.4
*/
function czr_fn_welcome_panel() {
$is_help = isset($_GET['help']) ? true : false;
$_faq_url = esc_url('http://docs.presscustomizr.com/category/90-faq-and-common-issues');
$_support_url = $this -> support_url;
$_theme_name = CZR_IS_PRO ? 'Customizr Pro' : 'Customizr';
do_action('__before_welcome_panel');
?>
%1$s %2$s %3$s :)',
__( "Thank you for using", "customizr" ),
$_theme_name,
CUSTOMIZR_VER
);
echo convert_smilies( $title );
?>
%1$s',
sprintf( __( "The best way to start with %s is to read the %s and visit the %s.", "customizr"),
$_theme_name,
sprintf( '%2$s', esc_url('docs.presscustomizr.com'), __("documentation", "customizr") ),
sprintf( '%2$s', esc_url('demo.presscustomizr.com'), __("demo website", "customizr") )
)
);
printf( '
ID => label
//Default in head
$selectable_sliders = array_merge( array(
-1 => __( '— Select a slider — ' , 'customizr' )
), $selectable_sliders );
//in case of sliders of images we set the label as the slider_id
if ( isset($sliders) && !empty( $sliders) )
foreach ( $sliders as $key => $value) {
if ( is_array( $value ) )
$selectable_sliders[ $key ] = $key;
}
?>
czr_fn_link_save( $post_id, $post_object );
//QUOTE
$this->czr_fn_quote_save( $post_id, $post_object );
//AUDIO
$this->czr_fn_audio_save( $post_id, $post_object );
//VIDEO
$this->czr_fn_video_save( $post_id, $post_object );
################# LAYOUT BOX #################
// verify this came from our screen and with proper authorization,
if ( isset( $_POST['post_layout_noncename']) && !wp_verify_nonce( $_POST['post_layout_noncename'], plugin_basename( __FILE__ ) ) )
return;
// OK, we're authenticated: we need to find and save the data
//set up the fields array
$tc_post_layout_fields = array(
'layout_field' => 'layout_key'
);
//if saving in a custom table, get post_ID
if ( isset( $_POST['post_ID'])) {
$post_ID = $_POST['post_ID'];
//sanitize user input by looping on the fields
foreach ( $tc_post_layout_fields as $tcid => $tckey) {
if ( isset( $_POST[$tcid])) {
$mydata = sanitize_text_field( $_POST[$tcid] );
// Do something with $mydata
// either using
add_post_meta( $post_ID, $tckey, $mydata, true) or
update_post_meta( $post_ID, $tckey , $mydata);
// or a custom table (see Further Reading section below)
}
}
}
################# SLIDER BOX #################
// verify this came from our screen and with proper authorization,
if ( isset( $_POST['post_slider_noncename']) && !wp_verify_nonce( $_POST['post_slider_noncename'], plugin_basename( __FILE__ ) ) )
return;
// OK, we're authenticated: we need to find and save the data
//set up the fields array
$tc_post_slider_fields = array(
'post_slider_check_field' => 'post_slider_check_key',
'slider_delay_field' => 'slider_delay_key',
'slider_layout_field' => 'slider_layout_key',
'slider_overlay_field' => 'slider_overlay_key',
'slider_dots_field' => 'slider_dots_key',
'post_slider_field' => 'post_slider_key',
);
//if saving in a custom table, get post_ID
if ( isset( $_POST['post_ID'])) {
do_action( '__before_save_post_slider_fields', $_POST, $tc_post_slider_fields );
$post_ID = $_POST['post_ID'];
//sanitize user input by looping on the fields
foreach ( $tc_post_slider_fields as $tcid => $tckey) {
if ( isset( $_POST[$tcid])) {
if ( in_array( $tcid, array( 'slider_overlay_field', 'slider_dots_field' ) ) ) {
$mydata = 0 == $_POST[$tcid] ? 'off' : 'on';
$mydata = sanitize_text_field( $mydata );
} else {
$mydata = sanitize_text_field( $_POST[$tcid] );
}
// Do something with $mydata
// either using
add_post_meta( $post_ID, $tckey, $mydata, true) or
update_post_meta( $post_ID, $tckey , $mydata);
// or a custom table (see Further Reading section below)
}
}
do_action( '__after_save_post_slider_fields', $_POST, $tc_post_slider_fields );
}
}
/**
* When the post/page is saved, saves our custom data for link
*/
function czr_fn_link_save( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( !isset($post_id) || !isset( $_POST['post_type'] ) || !isset( $_POST['format_link_noncename'] ) )
return $post_id;
if ( !wp_verify_nonce( $_POST['format_link_noncename'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( !current_user_can( 'edit_post' , $post_id ) )
return $post_id;
//check field existence
if ( !( isset( $_POST[ 'czr_link_title' ] ) && isset( $_POST[ 'czr_link_url' ] ) ) )
return $post_id;
if ( 'post' != $_POST[ 'post_type' ] )
return $post_id;
if ( 'link' != get_post_format( $post_id ) )
return $post_id;
//build custom post meta
$czr_link_format_meta = array(
'link_title' => sanitize_text_field( $_POST[ 'czr_link_title' ] ),
'link_url' => esc_url( $_POST[ 'czr_link_url' ] )
);
//update
add_post_meta( $post_id, 'czr_link_meta', $czr_link_format_meta, true ) or
update_post_meta( $post_id, 'czr_link_meta', $czr_link_format_meta );
}
/**
* When the post/page is saved, saves our custom data for quote
*/
function czr_fn_quote_save( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( !isset($post_id) || !isset( $_POST['post_type'] ) || !isset( $_POST['format_quote_noncename'] ) )
return $post_id;
if ( !wp_verify_nonce( $_POST['format_link_noncename'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( !current_user_can( 'edit_post' , $post_id ) )
return $post_id;
//check field existence
if ( !( isset( $_POST[ 'czr_quote_text' ] ) && isset( $_POST[ 'czr_quote_author' ] ) ) )
return $post_id;
if ( 'post' != $_POST[ 'post_type' ] )
return $post_id;
if ( 'quote' != get_post_format( $post_id ) )
return $post_id;
//build custom post meta
$czr_quote_format_meta = array(
'quote_text' => sanitize_text_field( $_POST[ 'czr_quote_text' ] ),
'quote_author' => sanitize_text_field( $_POST[ 'czr_quote_author' ] )
);
//update
add_post_meta( $post_id, 'czr_quote_meta', $czr_quote_format_meta, true ) or
update_post_meta( $post_id, 'czr_quote_meta', $czr_quote_format_meta );
}
/**
* When the post/page is saved, saves our custom data for audio
*/
function czr_fn_audio_save( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( !isset($post_id) || !isset( $_POST['post_type'] ) || !isset( $_POST['format_audio_noncename'] ) )
return $post_id;
if ( !wp_verify_nonce( $_POST['format_audio_noncename'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( !current_user_can( 'edit_post' , $post_id ) )
return $post_id;
//check field existence
if ( !( isset( $_POST[ 'czr_audio_url' ] ) ) )
return $post_id;
if ( 'post' != $_POST[ 'post_type' ] )
return $post_id;
if ( 'audio' != get_post_format( $post_id ) )
return $post_id;
//build custom post meta
$czr_audio_format_meta = array(
'audio_url' => esc_url( $_POST[ 'czr_audio_url' ] )
);
//update
add_post_meta( $post_id, 'czr_audio_meta', $czr_audio_format_meta, true ) or
update_post_meta( $post_id, 'czr_audio_meta', $czr_audio_format_meta );
}
/**
* When the post/page is saved, saves our custom data for video
*/
function czr_fn_video_save( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( !isset($post_id) || !isset( $_POST['post_type'] ) || !isset( $_POST['format_video_noncename'] ) )
return $post_id;
if ( !wp_verify_nonce( $_POST['format_video_noncename'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( !current_user_can( 'edit_post' , $post_id ) )
return $post_id;
//check field existence
if ( !( isset( $_POST[ 'czr_video_url' ] ) ) )
return $post_id;
if ( 'post' != $_POST[ 'post_type' ] )
return $post_id;
if ( 'video' != get_post_format( $post_id ) )
return $post_id;
//build custom post meta
$czr_video_format_meta = array(
'video_url' => esc_url( $_POST[ 'czr_video_url' ] )
);
//update
add_post_meta( $post_id, 'czr_video_meta', $czr_video_format_meta, true ) or
update_post_meta( $post_id, 'czr_video_meta', $czr_video_format_meta );
}
/*
----------------------------------------------------------------
------------------ ATTACHMENT SLIDER META BOX ------------------
----------------------------------------------------------------
*/
/**
* Add a slider metabox to attachments
* @package Customizr
* @since Customizr 2.0
*/
function czr_fn_attachment_meta_box( $id ) {//id, title, callback, post_type, context, priority, callback_args
if ( ! wp_attachment_is_image( $id ) )
return;
add_meta_box(
'slider_sectionid' ,
__( 'Slider Options' , 'customizr' ),
array( $this , 'czr_fn_attachment_slider_box' )
);
}
/**
* Prints the slider box content
* @package Customizr
* @since Customizr 2.0
*/
function czr_fn_attachment_slider_box( $post ) {
// Use nonce for verification
//wp_nonce_field( plugin_basename( __FILE__ ), 'slider_noncename' );
// The actual fields for data entry
//title check field setup
$slider_check_id = 'slider_check_field';
$slider_check_value = esc_attr(get_post_meta( $post->ID, $key = 'slider_check_key' , $single = true ));
?>
',
__('To add another slide : navigate to your media library (click on Media), open the edit screen of an image ( or add a new image ), and add it to your desired slider by using the dedicated option block at the bottom of the page.' , 'customizr'),
__('For more informations about sliders, check the documentation page :' , 'customizr'),
esc_url('http://docs.presscustomizr.com/search?query=slider'),
__('Slider documentation' , 'customizr')
);
?>
$tcvalue) {
switch ( $tckey) {
//delete slider
case 'delete_slider':
//first we delete the meta fields related to the deleted slider
//which screen are we coming from?
if( $tc_post_type == 'attachment' ) {
query_posts( 'meta_key=post_slider_key&meta_value='.$current_post_slider);
//we loop the posts with the deleted slider meta key
if(have_posts()) {
while ( have_posts() ) : the_post();
//delete the post meta
delete_post_meta(get_the_ID(), $key = 'post_slider_key' );
endwhile;
}
wp_reset_query();
}
//we delete from the post/page screen
else {
$post_slider_meta = esc_attr(get_post_meta( $post_ID, $key = 'post_slider_key' , $single = true ));
if(!empty( $post_slider_meta)) {
delete_post_meta( $post_ID, $key = 'post_slider_key' );
}
}
//in all cases, delete DB option
unset( $czr_options['tc_sliders'][$current_post_slider]);
//update DB with new slider array
update_option( 'tc_theme_options' , $czr_options );
break;
//reorder slides
case 'newOrder':
//turn new order into array
if(!empty( $tcvalue))
$neworder = explode( ',' , esc_attr( $tcvalue ));
//initialize the newslider array
$newslider = array();
foreach ( $neworder as $new_key => $new_index) {
$newslider[$new_index] = $czr_options['tc_sliders'][$current_post_slider][$new_index];
}
$czr_options['tc_sliders'][$current_post_slider] = $newslider;
//update DB with new slider array
update_option( 'tc_theme_options' , $czr_options );
break;
//sliders are added in options
case 'new_slider_name':
//check if we have something to save
$new_slider_name = esc_attr( $tcvalue );
$delete_slider = false;
if ( isset( $_POST['delete_slider']))
$delete_slider = $_POST['delete_slider'];
//prevent saving if we delete
if (!empty( $new_slider_name) && $delete_slider != true) {
$new_slider_name = wp_filter_nohtml_kses( $tcvalue );
//remove spaces and special char
$new_slider_name = strtolower(preg_replace("![^a-z0-9]+!i", "-", $new_slider_name));
$czr_options['tc_sliders'][$new_slider_name] = array( $post_ID);
//adds the new slider name in DB options
update_option( 'tc_theme_options' , $czr_options );
//associate the current post with the new saved slider
//looks for a previous slider entry and delete it
foreach ( $czr_options['tc_sliders'] as $slider_name => $slider) {
foreach ( $slider as $key => $tc_post) {
//clean empty values if necessary
if ( is_null( $czr_options['tc_sliders'][$slider_name][$key]))
unset( $czr_options['tc_sliders'][$slider_name][$key]);
//delete previous slider entries for this post
if ( $tc_post == $post_ID )
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
}
//update DB with clean option table
update_option( 'tc_theme_options' , $czr_options );
//push new post value for the new slider and write in DB
array_push( $czr_options['tc_sliders'][$new_slider_name], $post_ID);
update_option( 'tc_theme_options' , $czr_options );
}
break;
//post slider value
case 'post_slider_name':
//check if we display the attachment screen
if (!isset( $_POST['slider_check_field'])) {
break;
}
//we are in the attachment screen and we uncheck slider options checkbox
elseif ( $_POST['slider_check_field'] == 0) {
break;
}
//if we are in the slider creation case, the selected slider has to be the new one!
if (!empty( $new_slider_name))
break;
//check if we have something to save
$post_slider_name = esc_attr( $tcvalue );
//check if we have an input and if we are not in the slider creation case
if (!empty( $post_slider_name)) {
$post_slider_name = wp_filter_nohtml_kses( $post_slider_name );
//looks for a previous slider entry and delete it.
//Important : we check if the slider has slides first!
foreach ( $czr_options['tc_sliders'] as $slider_name => $slider) {
foreach ( $slider as $key => $tc_post) {
//clean empty values if necessary
if ( is_null( $czr_options['tc_sliders'][$slider_name][$key])) {
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
//clean slides with no images
$slide_img = wp_get_attachment_image( $czr_options['tc_sliders'][$slider_name][$key]);
if (isset($slide_img) && empty($slide_img)) {
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
//delete previous slider entries for this post
if ( $tc_post == $post_ID ) {
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
}//end for each
}
//update DB with clean option table
update_option( 'tc_theme_options' , $czr_options );
//check if the selected slider is empty and set it as array
if( empty( $czr_options['tc_sliders'][$post_slider_name]) ) {
$czr_options['tc_sliders'][$post_slider_name] = array();
}
//push new post value for the slider and write in DB
array_push( $czr_options['tc_sliders'][$post_slider_name], $post_ID);
update_option( 'tc_theme_options' , $czr_options );
}//end if !empty( $post_slider_name)
//No slider selected
else {
//looks for a previous slider entry and delete it
foreach ( $czr_options['tc_sliders'] as $slider_name => $slider) {
foreach ( $slider as $key => $tc_post) {
//clean empty values if necessary
if ( is_null( $czr_options['tc_sliders'][$slider_name][$key]))
unset( $czr_options['tc_sliders'][$slider_name][$key]);
//delete previous slider entries for this post
if ( $tc_post == $post_ID )
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
}
//update DB with clean option table
update_option( 'tc_theme_options' , $czr_options );
}
break;
}//end switch
}//end foreach
//POST META FIELDS
//set up the fields array
$tc_slider_fields = array(
//posts & pages
'post_slider_name' => 'post_slider_key' ,
'post_slider_check_field' => 'post_slider_check_key' ,
//attachments
'slider_check_field' => 'slider_check_key' ,
);
do_action( "__before_ajax_save_slider_{$tc_post_type}", $_POST, $tc_slider_fields );
//sanitize user input by looping on the fields
foreach ( $tc_slider_fields as $tcid => $tckey) {
if ( isset( $_POST[$tcid])) {
switch ( $tckey) {
//different sanitizations
//the slider name custom field for a post/page
case 'post_slider_key' :
$mydata = esc_attr( $_POST[$tcid] );
//Does the selected slider still exists in options? (we first check if the selected slider is not empty)
if(!empty( $mydata) && !isset( $czr_options['tc_sliders'][$mydata]))
break;
//write in DB
add_post_meta( $post_ID, $tckey, $mydata, true) or
update_post_meta( $post_ID, $tckey , $mydata);
break;
//inserted/updated in all cases
case 'post_slider_check_key':
case 'slider_check_key':
$mydata = esc_attr( $_POST[$tcid] );
//write in DB
add_post_meta( $post_ID, $tckey, $mydata, true) or
update_post_meta( $post_ID, $tckey , $mydata);
//check if we are in the attachment screen AND slider unchecked
if( $tckey == 'slider_check_key' && esc_attr( $_POST[$tcid] ) == 0) {
//if we uncheck the attachement slider, looks for a previous entry and delete it.
//Important : we check if the slider has slides first!
if ( isset( $czr_options['tc_sliders'])) {
foreach ( $czr_options['tc_sliders'] as $slider_name => $slider) {
foreach ( $slider as $key => $tc_post) {
//clean empty values if necessary
if ( is_null( $czr_options['tc_sliders'][$slider_name][$key]))
unset( $czr_options['tc_sliders'][$slider_name][$key]);
//delete previous slider entries for this post
if ( $tc_post == $post_ID )
unset( $czr_options['tc_sliders'][$slider_name][$key]);
}
}
}
//update DB with clean option table
update_option( 'tc_theme_options' , $czr_options );
}//endif;
break;
}//end switchendif;
}//end if ( isset( $_POST[$tcid])) {
}//end foreach
//attachments
if( $tc_post_type == 'attachment' )
$this->czr_fn_slide_save( $post_ID );
do_action( "__after_ajax_save_slider_{$tc_post_type}", $_POST, $tc_slider_fields );
}//function
/*
----------------------------------------------------------------
-------- AJAX CALL BACK FUNCTION (post and attachment) ---------
----------------------------------------------------------------
*/
/**
* Global slider ajax call back function : 1-Saves options and fields, 2-Renders
* Used in post or attachment context => uses post_slider var to check the context
* Works along with tc_ajax_slider.js
* @package Customizr
* @since Customizr 2.0
*/
function czr_fn_slider_cb() {
$nonce = $_POST['SliderCheckNonce'];
// check if the submitted nonce matches with the generated nonce we created earlier
if ( ! wp_verify_nonce( $nonce, 'tc-slider-check-nonce' ) ) {
die();
}
Try{
//get the post_id with the hidden input field
$tc_post_id = $_POST['tc_post_id'];
//save $_POST var in DB
$this->czr_fn_slider_ajax_save( $tc_post_id);
//check if we are in the post or attachment screen and select the appropriate rendering
//we use the post_slider var defined in tc_ajax_slider.js
if ( isset( $_POST['tc_post_type'])) {
if( $_POST['tc_post_type'] == 'post' ) {
$this->czr_fn_get_post_slider_infos( $tc_post_id );
}
else {
$this->czr_fn_get_attachment_slider_infos( $tc_post_id );
}
}
//echo $_POST['slider_id'];
} catch (Exception $e){
exit;
}
exit;
}
/**
* Loads the necessary scripts and stylesheets to display slider options
* @package Customizr
* @since Customizr 1.0
* @hook czr_slider_metabox_added
*/
function czr_fn_slider_admin_scripts( $post ) {
$_min_version = ( !$this->_minify_resources ) ? '' : '.min';
//load scripts only for creating and editing slides options in pages and posts
if ( did_action( 'tc_attachment_metabox_added' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
do_action( 'tc_enqueue_ajax_slider_before' );
//ajax refresh for slider options
wp_enqueue_script( 'czr_ajax_slider' ,
sprintf('%1$sback/js/tc_ajax_slider%2$s.js' , CZR_BASE_URL . CZR_ASSETS_PREFIX, $_min_version ),
array( 'jquery' ),
( defined('WP_DEBUG') && true === WP_DEBUG ) ? CUSTOMIZR_VER . time() : CUSTOMIZR_VER,
true
);
// Tips to declare javascript variables http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#bad-ways
wp_localize_script( 'czr_ajax_slider' , 'SliderAjax' , array(
// URL to wp-admin/admin-ajax.php to process the request
//'ajaxurl' => admin_url( 'admin-ajax.php' ),
// generate a nonce with a unique ID "myajax-post-comment-nonce"
// so that you can check it later when an AJAX request is sent
'SliderNonce' => wp_create_nonce( 'tc-slider-nonce' ),
'SliderCheckNonce' => wp_create_nonce( 'tc-slider-check-nonce' ),
)
);
//thickbox
wp_admin_css( 'thickbox' );
add_thickbox();
//sortable stuffs
wp_enqueue_style( 'sortablecss' ,
sprintf('%1$sback/css/tc_sortable%2$s.css' , CZR_BASE_URL . CZR_ASSETS_PREFIX, $_min_version )
);
//wp built-in color picker style and script
//Access the global $wp_version variable to see which version of WordPress is installed.
global $wp_version;
//If the WordPress version is greater than or equal to 3.5, then load the new WordPress color picker.
if ( 3.5 <= $wp_version ){
//Both the necessary css and javascript have been registered already by WordPress, so all we have to do is load them with their handle.
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
// load the minified version of custom script
wp_enqueue_script( 'cp_demo-custom' ,
sprintf('%1$sback/js/color-picker%2$s.js' , CZR_BASE_URL . CZR_ASSETS_PREFIX , $_min_version ),
array( 'jquery' , 'wp-color-picker' ),
true
);
}
//If the WordPress version is less than 3.5 load the older farbtasic color picker.
else {
//As with wp-color-picker the necessary css and javascript have been registered already by WordPress, so all we have to do is load them with their handle.
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
// load the minified version of custom script
wp_enqueue_script(
'cp_demo-custom' ,
sprintf('%1$sback/js/color-picker%2$s.js' , CZR_BASE_URL . CZR_ASSETS_PREFIX, $_min_version ),
array( 'jquery' , 'farbtastic' ),
( defined('WP_DEBUG') && true === WP_DEBUG ) ? CUSTOMIZR_VER . time() : CUSTOMIZR_VER,
true
);
}
do_action( 'tc_enqueue_ajax_slider_after' );
}
/**
* Loads the necessary scripts for the post formats metaboxes
* @package Customizr
* @since Customizr 4.0
* @hook czr_post_formats_metabox_added
*/
function czr_fn_post_formats_admin_scripts( $post ) {
$_ext = $this->_minify_resources ? '.min.js' : '.js';
wp_enqueue_script( 'czr-post-formats' ,
sprintf('%1$sback/js/czr_post_formats%2$s' , CZR_BASE_URL . CZR_ASSETS_PREFIX, $_ext ),
array( 'jquery', 'underscore' ),
$this->_resouces_version,
$in_footer = true
);
wp_localize_script( 'czr-post-formats',
'CZRPostFormatsParams' ,
array(
'postFormatSections' => $this->czr_fn_get_post_meta_boxes_map(),
'currentPostFormat' => get_post_format( $post ),
)
);
}
/*
----------------------------------------------------------------
------------- ATTACHMENT FIELDS FILTER IF WP < 3.5 -------------
----------------------------------------------------------------
*/
function czr_fn_attachment_filter( $form_fields, $post = null) {
$this->czr_fn_attachment_slider_box ( $post);
return $form_fields;
}
function czr_fn_attachment_save_filter( $post, $attachment ) {
if ( isset( $_POST['tc_post_id']))
$postid = $_POST['tc_post_id'];
$this->czr_fn_slide_save( $postid );
return $post;
}
/*
----------------------------------------------------------------
---------------------- STATIC FIELDS VIEWS ---------------------
----------------------------------------------------------------
*/
/**
* Build title element html
*
* @package Customizr
*/
public static function czr_fn_title_view( $args ) {
$defaults = array(
'title_tag' => 'h4',
'wrapper_class' => 'meta-box-item-title',
'wrapper_tag' => 'div',
'title_text' => '',
'echo' => 1,
'boxed' => 1,
);
$args = wp_parse_args( $args, $defaults );
extract($args);
$content = sprintf( '<%1$s>%2$s%1$s>', $title_tag, $title_text );
$html = $boxed ? CZR_meta_boxes::czr_fn_wrapper_view(
compact( 'content', 'wrapper_tag', 'wrapper_class')
) : $content;
if ( ! $echo )
return $html;
echo $html;
}
/**
* Build checkbox element html
*
* @package Customizr
*/
public static function czr_fn_checkbox_view( $args ) {
$defaults = array(
'input_name' => '',
'input_class' => 'czr-toggle-check__input',
'input_state' => '',
'echo' => 1,
'boxed' => 1,
'input_type' => 'checkbox',
'input_value' => '1',
'content_before' => '',
);
$args = wp_parse_args( $args, $defaults );
extract( $args );
CZR_meta_boxes::czr_fn_generic_input_view( array_merge( $args, array(
'content_before' => $content_before . '',
'custom_args' => checked( $input_state, $current = true, $c_echo = false),
'content_after' => ''
)));
}
/**
* Build selectbox element html
*
* @package Customizr
*/
public static function czr_fn_selectbox_view( $args ) {
$defaults = array(
'select_name' => '',
'select_class' => '',
'echo' => 1,
'boxed' => 1,
'content_before' => '',
'content_after' => '',
'choices' => array(),
'selected' => '',
'wrapper_tag' => 'div',
'wrapper_class' => 'meta-box-item-content',
);
$args = wp_parse_args( $args, $defaults );
extract($args);
if ( ! $choices ) return;
$select_id = isset($select_id) ? $select_id : $select_name;
$options_html = '';
foreach( $choices as $key => $label )
$options_html .= sprintf('',
esc_attr( $key ),
selected( $selected, esc_attr( $key ), $s_echo = false ),
$label
);
$content = sprintf('',
$select_name,
$select_id,
$options_html
);
$content = $content_before . $content . $content_after;
$html = $boxed ? CZR_meta_boxes::czr_fn_wrapper_view(
compact( 'content', 'wrapper_tag', 'wrapper_class')
) : $content;
$html = ! ( isset($title) && is_array( $title ) && ! empty( $title ) ) ? $html :
sprintf( "%s%s",
CZR_meta_boxes::czr_fn_title_view( array_merge($title, array( 'echo' => 0 ) ) ),
$html
);
if ( ! $echo )
return $html;
echo $html ;
}
/**
* Build generic input element html
*
* @package Customizr
*/
public static function czr_fn_generic_input_view( $args ) {
$defaults = array(
'input_name' => '',
'input_class' => 'widefat',
'input_type' => 'text',
'input_value' => '0',
'custom_args' => '',
'echo' => 1,
'boxed' => 1,
'content_before' => '',
'content_after' => '',
'wrapper_tag' => 'div',
'wrapper_class' => 'meta-box-item-content',
);
$args = wp_parse_args( $args, $defaults );
extract($args);
$input_id = isset($input_id) ? $input_id : $input_name;
$content = sprintf('',
esc_attr( $input_name ),
esc_attr( $input_id ),
esc_attr( $input_value ),
$custom_args,
$input_class,
$input_type
);
$content = $content_before . $content . $content_after;
$html = $boxed ? CZR_meta_boxes::czr_fn_wrapper_view(
compact( 'content', 'wrapper_tag', 'wrapper_class')
) : $content;
$html = ! ( isset($title) && is_array( $title ) && ! empty( $title ) ) ? $html :
sprintf( "%s%s",
CZR_meta_boxes::czr_fn_title_view( array_merge($title, array( 'echo' => 0 ) ) ),
$html
);
if ( ! $echo )
return $html;
echo $html ;
}
/**
* Build generic input element html
*
* @package Customizr
*/
public static function czr_fn_textarea_view( $args ) {
$defaults = array(
'input_name' => '',
'input_class' => 'widefat',
'input_value' => '0',
'custom_args' => '',
'echo' => 1,
'boxed' => 1,
'content_before' => '',
'content_after' => '',
'rows' => '5',
'cols' => '40',
'wrapper_tag' => 'div',
'wrapper_class' => 'meta-box-item-content',
);
$args = wp_parse_args( $args, $defaults );
extract($args);
$input_id = isset($input_id) ? $input_id : $input_name;
$content = sprintf('',
esc_attr( $input_name ),
esc_attr( $input_id ),
esc_attr( $input_value ),
$custom_args,
$input_class,
$rows,
$cols
);
$content = $content_before . $content . $content_after;
$html = $boxed ? CZR_meta_boxes::czr_fn_wrapper_view(
compact( 'content', 'wrapper_tag', 'wrapper_class')
) : $content;
$html = ! ( isset($title) && is_array( $title ) && ! empty( $title ) ) ? $html :
sprintf( "%s%s",
CZR_meta_boxes::czr_fn_title_view( array_merge($title, array( 'echo' => 0 ) ) ),
$html
);
if ( ! $echo )
return $html;
echo $html ;
}
/**
* Build generic content wrapper html
*
* @package Customizr
*/
public static function czr_fn_wrapper_view( $args ) {
$defaults = array(
'wrapper_tag' => 'div',
'wrapper_class' => 'meta-box-item-content',
'echo' => false,
'content' => ''
);
$args = wp_parse_args( $args, $defaults );
extract($args);
$html = sprintf('<%1$s class="%2$s">%3$s%1$s>',
$wrapper_tag,
$wrapper_class,
$content
);
if ( ! $echo )
return $html;
echo $html;
}
}//end of class
endif;
?>