post_type != SC_POST_TYPE ){
return;
}
$settings = Shortcoder::get_sc_settings( $post->ID );
echo '
';
echo ' ';
echo ' ';
echo '
';
echo '';
echo '
' . esc_html__( 'Your shortcode', 'shortcoder' ) . ': ';
echo '
' . esc_html( Shortcoder::get_sc_tag( $post->ID ) ) . '
';
echo '
' . esc_html__( 'Copy', 'shortcoder' ) . '';
echo '
' . esc_html__( 'Settings', 'shortcoder' ) . ' ';
echo '
';
// Editor
self::editor( $post, $settings );
// Hidden section
self::hidden_section( $post, $settings );
}
public static function add_meta_boxes(){
add_meta_box( 'sc_mb_settings', __( 'Shortcode settings', 'shortcoder' ), array( __CLASS__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' );
add_meta_box( 'sc_mb_more_plugins', __( 'Support', 'shortcoder' ), array( __CLASS__, 'more_plugins' ), SC_POST_TYPE, 'side', 'default' );
add_meta_box( 'sc_mb_links', __( 'WordPress News', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' );
remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' );
}
public static function settings_form( $post ){
wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
$settings = Shortcoder::get_sc_settings( $post->ID );
$fields = array(
array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array(
'value' => $post->post_title,
'name' => 'post_title',
'class' => 'widefat',
'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' )
))),
array( __( 'Description', 'shortcoder' ), SC_Admin_Form::field( 'textarea', array(
'value' => $settings[ '_sc_description' ],
'name' => '_sc_description',
'class' => 'widefat',
'helper' => __( 'Description of the shortcode for identification', 'shortcoder' )
))),
array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
'value' => $settings[ '_sc_disable_sc' ],
'name' => '_sc_disable_sc',
'list' => array(
'yes' => __( 'Yes', 'shortcoder' ),
'no' => __( 'No', 'shortcoder' )
),
'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' )
))),
array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
'value' => $settings[ '_sc_disable_admin' ],
'name' => '_sc_disable_admin',
'list' => array(
'yes' => __( 'Yes', 'shortcoder' ),
'no' => __( 'No', 'shortcoder' )
),
'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' )
))),
array( __( 'Execute shortcode on devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
'value' => $settings[ '_sc_allowed_devices' ],
'name' => '_sc_allowed_devices',
'list' => array(
'all' => __( 'All devices', 'shortcoder' ),
'desktop_only' => __( 'Desktop only', 'shortcoder' ),
'mobile_only' => __( 'Mobile only', 'shortcoder' )
),
'helper' => __( 'Select the devices where the shortcode should be executed. Note: If any caching plugin is used, a separate caching for desktop and mobile might be required.', 'shortcoder' )
))),
array( __( 'Execute blocks', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
'value' => $settings[ '_sc_execute_blocks' ],
'name' => '_sc_execute_blocks',
'list' => array(
'yes' => __( 'Yes', 'shortcoder' ),
'no' => __( 'No', 'shortcoder' )
),
'helper' => __( 'If the shortcode content contains WordPress blocks HTML, select yes to execute it. Note: The CSS/JS required for the blocks should be included on the page manually as required.', 'shortcoder' )
))),
);
echo SC_Admin_Form::table( apply_filters( 'sc_mod_sc_settings_fields', $fields, $settings ) );
}
public static function save_post( $post_id ){
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ){
return;
}
$default_settings = Shortcoder::default_sc_settings();
$skip_sanitize = array();
foreach( $default_settings as $key => $val ){
if( array_key_exists( $key, $_POST ) ){
if( in_array( $key, $skip_sanitize ) ){
$val = current_user_can( 'unfiltered_html' ) ? $_POST[ $key ] : wp_kses_post( $_POST[ $key ] );
}else{
$val = sanitize_text_field( $_POST[ $key ] );
}
update_post_meta( $post_id, $key, $val );
}
}
}
public static function before_insert_post( $post ){
if( $post[ 'post_type' ] != SC_POST_TYPE ){
return $post;
}
$post_title = sanitize_text_field( $post[ 'post_title' ] );
if( empty( $post_title ) ){
$post[ 'post_title' ] = sanitize_text_field( $post[ 'post_name' ] );
}
if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
$post[ 'post_content' ] = current_user_can( 'unfiltered_html' ) ? $_POST[ 'sc_content' ] : wp_kses_post( $_POST[ 'sc_content' ] );
}
return $post;
}
public static function editor_props( $settings ){
$g = SC_Admin::clean_get();
if( empty( $settings[ '_sc_editor' ] ) ){
$general_settings = Shortcoder::get_settings();
$settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ];
}
$list = apply_filters( 'sc_mod_editors', array(
'text' => __( 'Text editor', 'shortcoder' ),
'visual' => __( 'Visual editor', 'shortcoder' ),
'code' => __( 'Code editor', 'shortcoder' )
));
$editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
$switch = '';
$switch .= '';
foreach( $list as $id => $name ){
$switch .= '' . esc_html( $name ) . ' ';
}
$switch .= ' ';
$switch .= ' ';
return array(
'active' => $editor,
'switch_html' => $switch
);
}
public static function editor( $post, $settings ){
$editor = self::editor_props( $settings );
echo '';
echo '
';
echo ' ' . esc_html__( 'Insert shortcode parameters', 'shortcoder' ) . ' ';
echo $editor[ 'switch_html' ];
echo '
';
echo '
';
$post_data = get_post( $post->ID );
$post_content = $post_data->post_content;
if( SC_Admin::is_edit_page( 'new' ) ){
$general_settings = Shortcoder::get_settings();
$post_content = $general_settings[ 'default_content' ];
}
if( $editor[ 'active' ] == 'code' ){
echo '';
echo '';
}
if( in_array( $editor[ 'active' ], array( 'text', 'visual' ) ) ){
wp_editor( $post_content, 'sc_content', array(
'wpautop'=> false,
'textarea_rows'=> 20,
'tinymce' => ( $editor[ 'active' ] == 'visual' )
));
}
if( !current_user_can( 'unfiltered_html' ) ){
echo '' . esc_html__( 'Note: Your user role does not permit saving unrestricted HTML. Some tags and attributes will be removed before saving the content.', 'shortcoder' ) . '
';
}
do_action( 'sc_do_after_editor', $post, $settings, $editor );
}
public static function enqueue_scripts( $hook ){
global $post;
if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' || is_null( $post ) ){
return false;
}
$settings = Shortcoder::get_sc_settings( $post->ID );
$editor = self::editor_props( $settings );
wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
'active' => $editor[ 'active' ]
));
if( $editor[ 'active' ] != 'code' ){
return false;
}
$cm_settings = array();
$cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
'type' => 'htmlmixed'
));
wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
}
public static function custom_params_list(){
$sc_wp_params = Shortcoder::wp_params_list();
echo '';
foreach( $sc_wp_params as $group => $group_info ){
echo ' ';
echo esc_html( $group_info[ 'name' ] );
echo '';
foreach( $group_info[ 'params' ] as $param_id => $param_name ){
echo '' . esc_html( $param_name ) . ' ';
}
echo ' ';
}
echo ' ' . esc_html__( 'Custom parameter', 'shortcoder' ) . ' ';
echo ' ' . esc_html__( 'Custom Fields', 'shortcoder' ) . ' ';
echo ' ';
}
public static function hidden_section( $post, $settings ){
self::custom_params_list();
}
public static function feedback( $post ){
echo '';
echo '
Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.
';
echo '
Subscribe
';
echo '
';
}
public static function more_plugins( $post ){
echo '';
echo '
';
echo '
More WordPress plugins from us ';
echo '
';
echo '
';
}
public static function footer_text( $text ){
if( SC_Admin::is_sc_admin_page() ){
return '';
}
return $text;
}
}
SC_Admin_Edit::init();
?>