Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /************* GLOBAL CONTENT WIDTH ***************/
- if ( ! isset( $content_width ) ) {
- $content_width = 750;
- }
- if ( ! function_exists( 'cb_adjust_cw' ) ) {
- function cb_adjust_cw() {
- global $content_width, $post;
- if ( $post != NULL ) {
- $cb_post_id = $post->ID;
- $cb_fw_post = get_post_meta( $cb_post_id, 'cb_full_width_post', true );
- } else {
- $cb_fw_post = NULL;
- }
- if ( ( is_page_template( 'template-full-width.php' ) ) || ( $cb_fw_post == 'nosidebar' ) ) {
- $content_width = 1140;
- }
- }
- }
- add_theme_support( 'custom-header' );
- add_theme_support( 'custom-background' );
- add_theme_support( 'woocommerce' );
- add_action( 'template_redirect', 'cb_adjust_cw' );
- /************* LOAD NEEDED FILES ***************/
- require_once get_template_directory() . '/library/core.php';
- require_once get_template_directory() . '/library/translation/translation.php';
- // Fire Up The Framework
- add_filter( 'ot_show_pages', '__return_false' );
- add_filter( 'ot_show_new_layout', '__return_false' );
- add_filter( 'ot_theme_mode', '__return_true' );
- load_template( get_template_directory() . '/option-tree/ot-loader.php' );
- load_template( get_template_directory(). '/option-tree/includes/meta-boxes.php' );
- require_once get_template_directory().'/library/cb-to.php';
- require_once get_template_directory().'/library/cb-tgm.php';
- /************* THUMBNAIL SIZE OPTIONS *************/
- add_image_size('cb-80-60', 80, 60, true); // Used on sidebar widgets and small thumbnails
- add_image_size('cb-282-232', 282, 232, true ); // Slider 1
- add_image_size('cb-300-200', 300, 200, true ); // Used on Style A
- add_image_size('cb-300-250', 300, 250, true ); // Used on grids
- add_image_size('cb-360-240', 360, 240, true ); // Used on blog style B, Module B, Module C, Latest Post Widget Big Style
- add_image_size('cb-480-240', 480, 240, true ); // Used on featured post in mega menu
- add_image_size('cb-430-270', 430, 270, true ); // Used on slider widget, top review widget
- add_image_size('cb-400-250', 400, 250, true ); // Used on grid 5
- add_image_size('cb-600-250', 600, 250, true ); // Used on grid 4 and 6
- add_image_size('cb-600-400', 600, 400, true ); // Used on grid 4, 5 and 6
- add_image_size('cb-750-400', 750, 400, true ); // Used on standard featured image, slider 2 section b/d
- add_image_size('cb-1200-520', 1200, 520, true ); // Used on full-width featured image, slider 2 full-width
- add_image_size('cb-1400-700', 1400, 700, true ); // Used on Parallax/Full-background featured images
- if ( function_exists('buddypress') ) {
- if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) ) {
- define ( 'BP_AVATAR_FULL_WIDTH', 300 );
- }
- if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) ) {
- define ( 'BP_AVATAR_FULL_HEIGHT', 300 );
- }
- if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) ) {
- define ( 'BP_AVATAR_THUMB_HEIGHT', 80 );
- }
- if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) ) {
- define ( 'BP_AVATAR_THUMB_WIDTH', 80 );
- }
- }
- /*********************
- SCRIPTS & ENQUEUEING
- *********************/
- if (!is_admin()) {
- function blog_script() {
- //wp_enqueue_script('script-yandex', get_template_directory_uri() . '/library/js/yandex.js');
- }
- add_action('wp_enqueue_scripts', 'blog_script');
- if ( ! function_exists( 'cb_script_loaders' ) ) {
- function cb_script_loaders() {
- // enqueue base scripts and styles
- add_action('wp_enqueue_scripts', 'cb_scripts_and_styles', 999);
- // enqueue admin scripts and styles
- add_action('admin_enqueue_scripts', 'cb_post_admin_scripts_and_styles');
- // ie conditional wrapper
- add_filter( 'style_loader_tag', 'cb_ie_conditional', 10, 2 );
- }
- }
- add_action('after_setup_theme','cb_script_loaders', 15);
- if ( ! function_exists( 'cb_scripts_and_styles' ) ) {
- function cb_scripts_and_styles() {
- if (!is_admin()) {
- // Modernizr (without media query polyfill)
- wp_register_script( 'cb-modernizr', get_template_directory_uri(). '/library/js/modernizr.custom.min.js', array(), '2.6.2', false );
- wp_enqueue_script('cb-modernizr'); // enqueue it
- // Register main stylesheet for RTL/LTR
- if ( is_rtl() ) {
- wp_register_style( 'cb-main-stylesheet', get_template_directory_uri() . '/library/css/style-rtl.css', array(), '3.1', 'all' );
- } else {
- $cb_responsive_style = ot_get_option('cb_responsive_onoff', 'on');
- $cb_max_theme_width = ot_get_option('cb_max_theme_width', 'default');
- if ( $cb_responsive_style == 'on' ) {
- if ( $cb_max_theme_width == 'default' ) {
- wp_register_style( 'cb-main-stylesheet', get_template_directory_uri() . '/library/css/style.css', array(), '3.1', 'all' );
- } else {
- wp_register_style( 'cb-main-stylesheet', get_template_directory_uri() . '/library/css/style-1020px.css', array(), '3.1', 'all' );
- }
- } else {
- if ( $cb_max_theme_width == 'default' ) {
- wp_register_style( 'cb-main-stylesheet', get_template_directory_uri() . '/library/css/style-unresponsive.css', array(), '3.1', 'all' );
- } else {
- wp_register_style( 'cb-main-stylesheet', get_template_directory_uri() . '/library/css/style-1020px-unresponsive.css', array(), '3.1', 'all' );
- }
- }
- }
- wp_enqueue_style('cb-main-stylesheet'); // enqueue it
- // Register fonts
- $cb_font = cb_fonts();
- wp_register_style( 'cb-font-stylesheet', $cb_font[0], array(), '3.1', 'all' );
- wp_enqueue_style('cb-font-stylesheet'); // enqueue it
- // register font awesome stylesheet
- wp_register_style('fontawesome', get_template_directory_uri(). '/library/css/fontawesome/css/font-awesome.min.css', array(), '4.1.0', 'all');
- wp_enqueue_style('fontawesome'); // enqueue it
- // ie-only stylesheet
- wp_register_style( 'cb-ie-only', get_template_directory_uri(). '/library/css/ie.css', array(), '3.1' );
- wp_enqueue_style('cb-ie-only'); // enqueue it
- if ( class_exists('Woocommerce') ) {
- wp_register_style( 'cb-woocommerce-stylesheet', get_template_directory_uri() . '/woocommerce/css/woocommerce.css', array(), '3.1', 'all' );
- wp_enqueue_style('cb-woocommerce-stylesheet'); // enqueue it
- }
- // comment reply script for threaded comments
- if ( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
- global $wp_scripts;
- $wp_scripts->add_data( 'comment-reply', 'group', 1 );
- wp_enqueue_script( 'comment-reply' ); // enqueue it
- }
- // Load Flexslider
- wp_register_script( 'cb-flexslider', get_template_directory_uri() . '/library/js/jquery.flexslider-min.js', array( 'jquery' ),'', true);
- wp_enqueue_script( 'cb-flexslider' ); // enqueue it
- if ( is_single() == true) {
- // Load Cookie
- wp_register_script( 'cb-cookie', get_template_directory_uri() . '/library/js/cookie.min.js', array( 'jquery' ),'', true);
- wp_enqueue_script( 'cb-cookie' ); // enqueue it
- }
- // Load Selectivizr
- wp_register_script( 'cb-select', get_template_directory_uri() . '/library/js/selectivizr-min.js', array( 'jquery' ),'', true);
- wp_enqueue_script( 'cb-select' ); // enqueue it
- // Load lightbox
- $cb_lightbox_onoff = ot_get_option('cb_lightbox_onoff', 'on');
- if ( $cb_lightbox_onoff != 'off' ) {
- wp_register_script( 'cb-lightbox', get_template_directory_uri() . '/library/js/jquery.fs.boxer.min.js', array( 'jquery' ),'', true);
- wp_enqueue_script( 'cb-lightbox' ); // enqueue it
- }
- // Load Extra Needed Javascript
- wp_register_script( 'cb-js-ext', get_template_directory_uri() . '/library/js/jquery.ext.js', array( 'jquery' ),'', true);
- wp_enqueue_script( 'cb-js-ext' ); // enqueue it
- // Load scripts
- wp_register_script( 'cb-js', get_template_directory_uri() . '/library/js/cb-scripts.js', array( 'jquery' ), '3.1' , true);
- wp_enqueue_script( 'cb-js' ); // enqueue it
- }
- }
- }
- if ( ! function_exists( 'cb_post_admin_scripts_and_styles' ) ) {
- function cb_post_admin_scripts_and_styles($hook) {
- // loading admin styles only on edit + posts + new posts
- if ( $hook == 'widgets.php' || $hook == 'post.php' || $hook == 'post-new.php' || $hook == 'profile.php' || $hook == 'appearance_page_ot-theme-options' || $hook == 'user-edit.php' || $hook == 'edit-tags.php' ) {
- wp_register_style( 'cb-admin-css', get_template_directory_uri(). '/library/css/admin.css', array(), '3.1' );
- wp_enqueue_style('cb-admin-css'); // enqueue it
- wp_register_script( 'admin-js', get_template_directory_uri() . '/library/js/cb-admin.js', array(), '3.1', true);
- wp_enqueue_script( 'admin-js' ); // enqueue it
- wp_enqueue_script( 'suggest' ); // enqueue it
- }
- }
- }
- // adding the conditional wrapper around ie8 stylesheet
- // source: Gary Jones - http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
- // GPLv2 or newer license
- if ( ! function_exists( 'cb_ie_conditional' ) ) {
- function cb_ie_conditional( $tag, $handle ) {
- if ( ( 'cb-ie-only' == $handle ) || ( 'cb-select' == $handle ) ) {
- $tag = '<!--[if lt IE 9]>' . "\n" . $tag . '<![endif]-->' . "\n";
- }
- return $tag;
- }
- }
- // Sidebars & Widgetizes Areas
- if ( ! function_exists( 'cb_register_sidebars' ) ) {
- function cb_register_sidebars() {
- $cb_footer_layout = ot_get_option('cb_footer_layout', 'cb-footer-a');
- // Main Sidebar
- register_sidebar(array(
- 'name' => 'Global Sidebar',
- 'id' => 'sidebar-global',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- // After Post
- register_sidebar(array(
- 'name' => 'After Post',
- 'id' => 'after-post',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-block-title">',
- 'after_title' => '</h3>'
- ));
- // Footer Widget 1
- register_sidebar( array(
- 'name' => 'Footer 1',
- 'id' => 'footer-1',
- 'before_widget' => '<div id="%1$s" class="cb-footer-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-footer-widget-title"><span>',
- 'after_title' => '</span></h3>'
- ));
- // Footer Widget 2
- register_sidebar( array(
- 'name' => 'Footer 2',
- 'id' => 'footer-2',
- 'before_widget' => '<div id="%1$s" class="cb-footer-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-footer-widget-title"><span>',
- 'after_title' => '</span></h3>'
- ));
- // Footer Widget 3
- register_sidebar( array(
- 'name' => 'Footer 3',
- 'id' => 'footer-3',
- 'before_widget' => '<div id="%1$s" class="cb-footer-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-footer-widget-title"><span>',
- 'after_title' => '</span></h3>'
- ));
- if ( $cb_footer_layout == 'cb-footer-b' ) {
- // Footer Widget 4
- register_sidebar( array(
- 'name' => 'Footer 4',
- 'id' => 'footer-4',
- 'before_widget' => '<div id="%1$s" class="cb-footer-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-footer-widget-title"><span>',
- 'after_title' => '</span></h3>'
- ));
- }
- register_sidebar(
- array(
- 'name' => 'Valenti Multi-Widgets Area',
- 'id' => 'cb_multi_widgets',
- 'description' => '1- Drag multiple widgets here 2- Drag the "Valenti Multi-Widget Widget" to the sidebar where you want to show the multi-widgets.',
- 'before_widget' => '<div id="%1$s" class="widget cb-multi-widget tabbertab %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>'
- )
- );
- if ( function_exists( 'bbpress' ) ) {
- register_sidebar( array(
- 'name' => 'bbPress Sidebar',
- 'id' => 'sidebar-bbpress',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- }
- if ( function_exists( 'buddypress' ) ) {
- register_sidebar( array(
- 'name' => 'BuddyPress Sidebar',
- 'id' => 'sidebar-buddypress',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- }
- if ( class_exists( 'Woocommerce' ) ) {
- register_sidebar( array(
- 'name' => 'WooCommerce Sidebar',
- 'id' => 'sidebar-woocommerce',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- }
- $cb_pages = get_pages( array( 'post_status' => array('publish', 'pending', 'private', 'draft') ) );
- foreach ( $cb_pages as $page ) {
- $cb_custom_fields = get_post_custom($page->ID);
- if ( isset( $cb_custom_fields['cb_page_custom_sidebar'][0] ) ) { $cb_page_sidebar = $cb_custom_fields['cb_page_custom_sidebar'][0]; } else { $cb_page_sidebar = 'off'; }
- if ( isset( $cb_custom_fields['_wp_page_template'][0] ) ) { $cb_page_template = $cb_custom_fields['_wp_page_template'][0]; } else { $cb_page_template = 'off'; }
- if ( ( $cb_page_sidebar == '2' ) && ( $cb_page_template != 'page-valenti-builder.php' ) ) {
- register_sidebar( array(
- 'name' => $page->post_title .' (Page)',
- 'id' => 'page-'.$page->ID . '-sidebar',
- 'description' => 'This is the ' . $page->post_title . ' sidebar',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ) );
- }
- if ( $cb_page_template == 'page-valenti-builder.php' ) {
- // Homepage Section B Sidebar
- register_sidebar(array(
- 'name' => 'Section B Sidebar ('.$page->post_title .' page)',
- 'id' => 'sidebar-hp-b-'.$page->ID,
- 'description' => 'Page: ' . $page->post_title,
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- // Homepage Section D Sidebar
- register_sidebar(array(
- 'name' => 'Section D Sidebar (' . $page->post_title . ' page)',
- 'id' => 'sidebar-hp-d-' . $page->ID,
- 'description' => 'This is Sidebar D for ' . $page->post_title,
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ));
- }
- }
- if ( function_exists('get_tax_meta') ) {
- $cb_categories = get_categories( array( 'hide_empty'=> 0 ) );
- foreach ( $cb_categories as $cb_cat ) {
- $cb_cat_onoff = get_tax_meta( $cb_cat->cat_ID, 'cb_cat_sidebar');
- if ( $cb_cat_onoff == 'on' ) {
- register_sidebar( array(
- 'name' => $cb_cat->cat_name,
- 'id' => $cb_cat->category_nicename . '-sidebar',
- 'description' => 'This is the ' . $cb_cat->cat_name . ' sidebar',
- 'before_widget' => '<div id="%1$s" class="cb-sidebar-widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="cb-sidebar-widget-title">',
- 'after_title' => '</h3>'
- ) );
- }
- }
- }
- }
- }
- add_filter( 'ot_post_formats', '__return_true' );
- if ( ! function_exists( 'cb_ot_meta_box_post_format_video' ) ) {
- function cb_ot_meta_box_post_format_video() {
- return array(
- 'id' => 'ot-post-format-video',
- 'title' => 'Valenti Post Format: Video',
- 'desc' => '',
- 'pages' => 'post',
- 'context' => 'side',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'id' => 'cb_video_embed_code_post',
- 'label' => '',
- 'desc' => 'Video iframe embed code',
- 'std' => '',
- 'type' => 'textarea'
- )
- )
- );
- }
- }
- add_filter( 'ot_meta_box_post_format_video', 'cb_ot_meta_box_post_format_video' );
- if ( ! function_exists( 'cb_ot_meta_box_post_format_gallery' ) ) {
- function cb_ot_meta_box_post_format_gallery() {
- return array(
- 'id' => 'ot-post-format-gallery',
- 'title' => 'Valenti Post Format: Gallery',
- 'desc' => '',
- 'pages' => 'post',
- 'context' => 'side',
- 'priority' => 'low',
- 'fields' => array(
- )
- );
- }
- }
- add_filter( 'ot_meta_box_post_format_gallery', 'cb_ot_meta_box_post_format_gallery' );
- if ( ! function_exists( 'cb_ot_meta_box_post_format_audio' ) ) {
- function cb_ot_meta_box_post_format_audio() {
- return array(
- 'id' => 'ot-post-format-audio',
- 'title' => __( 'Valenti Post Format: Audio', 'option-tree' ),
- 'desc' => '',
- 'pages' => 'post',
- 'context' => 'side',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'id' => 'cb_soundcloud_embed_code_post',
- 'label' => '',
- 'desc' => 'Audio Embed Code',
- 'std' => '',
- 'type' => 'textarea'
- )
- )
- );
- }
- }
- add_filter( 'ot_meta_box_post_format_audio', 'cb_ot_meta_box_post_format_audio' );
- if ( ! function_exists( 'cb_ot_type_radio_image_src' ) ) {
- function cb_ot_type_radio_image_src( $src ) {
- return get_template_directory_uri() . '/option-tree/assets/images/options' . $src;
- }
- }
- add_filter( 'ot_type_radio_image_src', 'cb_ot_type_radio_image_src' );
- if ( ! function_exists( 'cb_ot_upload_text' ) ) {
- function cb_ot_upload_text() {
- return 'Insert';
- }
- }
- add_filter( 'ot_upload_text', 'cb_ot_upload_text' );
- if ( ! function_exists( 'cb_ot_header_version_text' ) ) {
- function cb_ot_header_version_text() {
- return '';
- }
- }
- add_filter( 'ot_header_version_text', 'cb_ot_header_version_text' );
- if ( ! function_exists( 'cb_ot_header_logo_link' ) ) {
- function cb_ot_header_logo_link() {
- return '<img src="' . get_template_directory_uri() . '/option-tree/assets/images/logo.png">';
- }
- }
- add_filter( 'ot_header_logo_link', 'cb_ot_header_logo_link' );
- /*
- *
- * Age Limit
- *
- * */
- /* Добавляем блоки в основную колонку на страницах постов и пост. страниц */
- if ( ! function_exists( 'agelimit_add_custom_box' ) ) {
- function agelimit_add_custom_box() {
- $screens = array( 'post', 'page' );
- foreach ( $screens as $screen ) {
- add_meta_box( 'agelimit', __( "Age Limit", 'agelimit' ), 'agelimit_meta_box_callback', $screen, 'side' );
- }
- }
- }
- add_action( 'add_meta_boxes', 'agelimit_add_custom_box' );
- /* HTML код блока */
- if ( ! function_exists( 'agelimit_meta_box_callback' ) ) {
- function agelimit_meta_box_callback() {
- // Используем nonce для верификации
- wp_nonce_field( plugin_basename( __FILE__ ), 'agelimit_noncename' );
- global $post;
- $agelimit_value = get_post_meta( $post->ID, 'agelimit_plugin_value', true );
- // Поля формы для введения данных
- echo '<label for="agelimit_plugin_value">' . __( "Age Limit", 'agelimit' ) . '</label> ';
- echo '
- <select id="agelimit_plugin_value" name="agelimit_plugin_value">
- <option value="0"> ' . __( "No", 'agelimit' ) . ' </option>
- <option value="3" ' . ( $agelimit_value == '3' ? ' selected="selected" ' : ' ' ) . '> 3+ </option>
- <option value="7" ' . ( $agelimit_value == '7' ? ' selected="selected" ' : ' ' ) . '> 7+ </option>
- <option value="12" ' . ( $agelimit_value == '12' ? ' selected="selected" ' : ' ' ) . '> 12+ </option>
- <option value="16" ' . ( $agelimit_value == '16' ? ' selected="selected" ' : ' ' ) . '> 16+ </option>
- <option value="18" ' . ( $agelimit_value == '18' ? ' selected="selected" ' : ' ' ) . '> 18+ </option>
- </select>
- ';
- }
- }
- /* Сохраняем данные, когда пост сохраняется */
- if ( ! function_exists( 'agelimit_save_postdata' ) ) {
- function agelimit_save_postdata( $post_id ) {
- // проверяем nonce нашей страницы, потому что save_post может быть вызван с другого места.
- if ( ! wp_verify_nonce( $_POST['agelimit_noncename'], plugin_basename( __FILE__ ) ) ) {
- return $post_id;
- }
- // проверяем, если это автосохранение ничего не делаем с данными нашей формы.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // проверяем разрешено ли пользователю указывать эти данные
- if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Убедимся что поле установлено.
- if ( ! isset( $_POST['agelimit_plugin_value'] ) ) {
- return $post_id;
- }
- // Все ОК.
- // Обновляем данные в базе данных.
- update_post_meta( $post_id, 'agelimit_plugin_value', intval( $_POST['agelimit_plugin_value'] ) );
- return $post_id;
- }
- }
- add_action( 'save_post', 'agelimit_save_postdata' );
- /*Вывод блока ограничений*/
- if ( ! function_exists( 'agelimit_box' ) ) {
- function agelimit_box() {
- global $post;
- $agelimit_value = get_post_meta( $post->ID, 'agelimit_plugin_value', true );
- if ( ! empty( $agelimit_value ) ) {
- echo '
- <div class="agelimit_box">' . $agelimit_value . '+</div>
- ';
- }
- return;
- }
- }
- add_shortcode( 'agelimit_box', 'agelimit_box' );
- /*
- *
- * Game Box
- *
- * */
- /* Добавляем блоки в основную колонку на страницах постов и пост. страниц */
- if ( ! function_exists( 'gamebox_add_custom_box' ) ) {
- function gamebox_add_custom_box() {
- $screens = array( 'post', 'page' );
- foreach ( $screens as $screen ) {
- add_meta_box( 'gamebox', __( "Game Properties", 'gamebox' ), 'gamebox_meta_box_callback', $screen );
- }
- }
- }
- add_action( 'add_meta_boxes', 'gamebox_add_custom_box' );
- /* HTML код блока */
- if ( ! function_exists( 'gamebox_meta_box_callback' ) ) {
- function gamebox_meta_box_callback() {
- global $post;
- //получаем текущую категорию
- $cur_post = get_the_category( $post->ID );
- $cur_post = current( $cur_post );
- $cur_post_cat_id = $cur_post->cat_ID;
- //получаем список категорий игр
- $cats = array();
- //получаем список категорий
- $categories_info = get_categories(
- array(
- 'child_of' => 3, //игры
- 'hide_empty' => 0
- )
- );
- foreach ( (array) $categories_info as $_info ) {
- $cats[ $_info->term_id ] = $_info->term_id;
- }
- if ( ! in_array( $cur_post_cat_id, $cats ) ) {
- echo '<span>Current post is not in the category of games.</span>';
- return;
- }
- // Используем nonce для верификации
- wp_nonce_field( plugin_basename( __FILE__ ), 'gamebox_noncename' );
- global $post;
- global $wpdb;
- //проверяем таблицу
- genres_check_tbl();
- echo '
- <style>
- .gamebox_box_input{
- width: 100%;
- }
- .gamebox_timestamp {
- line-height: 30px;
- }
- .gamebox_timestamp input, .gamebox_timestamp select {
- height: 26px;
- vertical-align: top;
- }
- .gamebox_timestamp .gamebox_dd {
- width: 2em;
- }
- .gamebox_timestamp .gamebox_yyyy {
- width: 3.4em;
- }
- .gamebox_timestamp_platform select {
- vertical-align: top;
- }
- </style>
- <div class="gamebox_box">
- ';
- //Альтернативное название игры
- echo '
- <label>' . __( 'Alternative Title', 'gamebox' ) . '</label><br/>
- <input class="gamebox_box_input" type="text" name="gamebox_alt_title" value="' . get_post_meta( $post->ID, 'gamebox_alt_title', true ) . '" /><br/>
- ';
- //Разработчик
- echo '
- <label>' . __( 'Developer', 'gamebox' ) . '</label><br/>
- <input class="gamebox_box_input" type="text" name="gamebox_developer" value="' . get_post_meta( $post->ID, 'gamebox_developer', true ) . '" /><br/>
- ';
- //Издатель
- echo '
- <label>' . __( 'Publisher', 'gamebox' ) . '</label><br/>
- <input class="gamebox_box_input" type="text" name="gamebox_publisher" value="' . get_post_meta( $post->ID, 'gamebox_publisher', true ) . '" /><br/>
- ';
- //Издатель ru
- echo '
- <label>' . __( 'Publisher in Russia', 'gamebox' ) . '</label><br/>
- <input class="gamebox_box_input" type="text" name="gamebox_publisher_ru" value="' . get_post_meta( $post->ID, 'gamebox_publisher_ru', true ) . '" /><br/>
- ';
- //Дата выхода
- $unix_date = get_post_meta( $post->ID, 'gamebox_date', true );
- if ( ! empty( $unix_date ) ) {
- $mm = date( "m", $unix_date );
- $dd = date( "d", $unix_date );
- $yyyy = date( "Y", $unix_date );
- }
- echo '
- <label>' . __( 'Released Date', 'gamebox' ) . '</label><br/>
- <div class="gamebox_timestamp">
- <select name="gamebox_mm">
- <option value="00"> </option>
- <option value="01" ' . ( $mm == '01' ? ' selected="selected" ' : ' ' ) . '>01-Jan</option>
- <option value="02" ' . ( $mm == '02' ? ' selected="selected" ' : ' ' ) . '>02-Feb</option>
- <option value="03" ' . ( $mm == '03' ? ' selected="selected" ' : ' ' ) . '>03-Mar</option>
- <option value="04" ' . ( $mm == '04' ? ' selected="selected" ' : ' ' ) . '>04-Apr</option>
- <option value="05" ' . ( $mm == '05' ? ' selected="selected" ' : ' ' ) . '>05-May</option>
- <option value="06" ' . ( $mm == '06' ? ' selected="selected" ' : ' ' ) . '>06-Jun</option>
- <option value="07" ' . ( $mm == '07' ? ' selected="selected" ' : ' ' ) . '>07-Jul</option>
- <option value="08" ' . ( $mm == '08' ? ' selected="selected" ' : ' ' ) . '>08-Aug</option>
- <option value="09" ' . ( $mm == '09' ? ' selected="selected" ' : ' ' ) . '>09-Sep</option>
- <option value="10" ' . ( $mm == '10' ? ' selected="selected" ' : ' ' ) . '>10-Oct</option>
- <option value="11" ' . ( $mm == '11' ? ' selected="selected" ' : ' ' ) . '>11-Nov</option>
- <option value="12" ' . ( $mm == '12' ? ' selected="selected" ' : ' ' ) . '>12-Dec</option>
- </select>
- <input type="text" autocomplete="off" maxlength="2" size="2" value="' . $dd . '" name="gamebox_dd" class="gamebox_dd">,
- <input type="text" autocomplete="off" maxlength="4" size="4" value="' . $yyyy . '" name="gamebox_yyyy" class="gamebox_yyyy">
- </div>
- ';
- //Дата выхода ru
- $unix_date = get_post_meta( $post->ID, 'gamebox_date_ru', true );
- if ( ! empty( $unix_date ) ) {
- $mm = date( "m", $unix_date );
- $dd = date( "d", $unix_date );
- $yyyy = date( "Y", $unix_date );
- }
- echo '
- <label>' . __( 'Released Date in Russia', 'gamebox' ) . '</label><br/>
- <div class="gamebox_timestamp">
- <select name="gamebox_mm_ru">
- <option value="00"> </option>
- <option value="01" ' . ( $mm == '01' ? ' selected="selected" ' : ' ' ) . '>01-Jan</option>
- <option value="02" ' . ( $mm == '02' ? ' selected="selected" ' : ' ' ) . '>02-Feb</option>
- <option value="03" ' . ( $mm == '03' ? ' selected="selected" ' : ' ' ) . '>03-Mar</option>
- <option value="04" ' . ( $mm == '04' ? ' selected="selected" ' : ' ' ) . '>04-Apr</option>
- <option value="05" ' . ( $mm == '05' ? ' selected="selected" ' : ' ' ) . '>05-May</option>
- <option value="06" ' . ( $mm == '06' ? ' selected="selected" ' : ' ' ) . '>06-Jun</option>
- <option value="07" ' . ( $mm == '07' ? ' selected="selected" ' : ' ' ) . '>07-Jul</option>
- <option value="08" ' . ( $mm == '08' ? ' selected="selected" ' : ' ' ) . '>08-Aug</option>
- <option value="09" ' . ( $mm == '09' ? ' selected="selected" ' : ' ' ) . '>09-Sep</option>
- <option value="10" ' . ( $mm == '10' ? ' selected="selected" ' : ' ' ) . '>10-Oct</option>
- <option value="11" ' . ( $mm == '11' ? ' selected="selected" ' : ' ' ) . '>11-Nov</option>
- <option value="12" ' . ( $mm == '12' ? ' selected="selected" ' : ' ' ) . '>12-Dec</option>
- </select>
- <input type="text" autocomplete="off" maxlength="2" size="2" value="' . $dd . '" name="gamebox_dd_ru" class="gamebox_dd">,
- <input type="text" autocomplete="off" maxlength="4" size="4" value="' . $yyyy . '" name="gamebox_yyyy_ru" class="gamebox_yyyy">
- </div>
- ';
- echo "<br>";
- //Жанр
- $genres_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "genres WHERE 1", "ARRAY_A" );
- $genres_post = explode( ",", get_post_meta( $post->ID, 'gamebox_genres', true ) );
- echo '
- <label>' . __( 'Genres', 'gamebox' ) . '</label><br/>
- ';
- foreach ( (array) $genres_data as $_name => $_info ) {
- $checked = "";
- if ( in_array( $_info["id"], $genres_post ) ) {
- $checked = ' checked="checked" ';
- }
- echo '
- <label class="selectit"><input type="checkbox" ' . $checked . ' name="gamebox_genres[]" value="' . $_info["id"] . '"> ' . $_info["name"] . '</label><br/>
- ';
- }
- echo "<br>";
- //Платформа
- $platforms_info = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "platforms WHERE 1", "ARRAY_A" );
- $platforms_post = explode( ",", get_post_meta( $post->ID, 'gamebox_platforms', true ) );
- $platforms_dates = get_post_meta( $post->ID, 'gamebox_platforms_dates', true );
- echo '
- <label>' . __( 'Platforms', 'gamebox' ) . '</label><br/>
- ';
- foreach ( (array) $platforms_info as $_name => $_info ) {
- $checked = "";
- $mm = "";
- $dd = "";
- $yyyy = "";
- if ( in_array( $_info["id"], $platforms_post ) ) {
- $checked = ' checked="checked" ';
- }
- if ( ! empty( $platforms_dates[ $_info["id"] ] ) ) {
- $mm = date( "m", $platforms_dates[ $_info["id"] ] );
- $dd = date( "d", $platforms_dates[ $_info["id"] ] );
- $yyyy = date( "Y", $platforms_dates[ $_info["id"] ] );
- }
- echo '
- <div>
- <label class="selectit" style="float:left; min-width:200px;"><input type="checkbox" ' . $checked . ' name="gamebox_platforms[' . $_info["id"] . ']" value="' . $_info["id"] . '"> ' . $_info["name"] . '</label>
- <div class="gamebox_timestamp_platform">
- <select name="gamebox_platform_mm[' . $_info["id"] . ']">
- <option value="00"> </option>
- <option value="01" ' . ( $mm == '01' ? ' selected="selected" ' : ' ' ) . '>01-Jan</option>
- <option value="02" ' . ( $mm == '02' ? ' selected="selected" ' : ' ' ) . '>02-Feb</option>
- <option value="03" ' . ( $mm == '03' ? ' selected="selected" ' : ' ' ) . '>03-Mar</option>
- <option value="04" ' . ( $mm == '04' ? ' selected="selected" ' : ' ' ) . '>04-Apr</option>
- <option value="05" ' . ( $mm == '05' ? ' selected="selected" ' : ' ' ) . '>05-May</option>
- <option value="06" ' . ( $mm == '06' ? ' selected="selected" ' : ' ' ) . '>06-Jun</option>
- <option value="07" ' . ( $mm == '07' ? ' selected="selected" ' : ' ' ) . '>07-Jul</option>
- <option value="08" ' . ( $mm == '08' ? ' selected="selected" ' : ' ' ) . '>08-Aug</option>
- <option value="09" ' . ( $mm == '09' ? ' selected="selected" ' : ' ' ) . '>09-Sep</option>
- <option value="10" ' . ( $mm == '10' ? ' selected="selected" ' : ' ' ) . '>10-Oct</option>
- <option value="11" ' . ( $mm == '11' ? ' selected="selected" ' : ' ' ) . '>11-Nov</option>
- <option value="12" ' . ( $mm == '12' ? ' selected="selected" ' : ' ' ) . '>12-Dec</option>
- </select>
- <input type="text" autocomplete="off" maxlength="2" size="2" value="' . $dd . '" name="gamebox_platform_dd[' . $_info["id"] . ']" class="gamebox_platform_dd">,
- <input type="text" autocomplete="off" maxlength="4" size="4" value="' . $yyyy . '" name="gamebox_platform_yyyy[' . $_info["id"] . ']" class="gamebox_platform_yyyy">
- </div>
- </div>
- ';
- }
- echo "<br>";
- echo '</div>';
- }
- }
- /* Сохраняем данные, когда пост сохраняется */
- if ( ! function_exists( 'gamebox_save_postdata' ) ) {
- function gamebox_save_postdata( $post_id ) {
- // проверяем nonce нашей страницы, потому что save_post может быть вызван с другого места.
- if ( ! wp_verify_nonce( $_POST['gamebox_noncename'], plugin_basename( __FILE__ ) ) ) {
- return $post_id;
- }
- // проверяем, если это автосохранение ничего не делаем с данными нашей формы.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // проверяем разрешено ли пользователю указывать эти данные
- if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Обновляем данные в базе данных.
- if ( isset( $_POST['gamebox_alt_title'] ) ) {
- update_post_meta( $post_id, 'gamebox_alt_title', sanitize_text_field( $_POST['gamebox_alt_title'] ) );
- }
- if ( isset( $_POST['gamebox_developer'] ) ) {
- update_post_meta( $post_id, 'gamebox_developer', sanitize_text_field( $_POST['gamebox_developer'] ) );
- }
- if ( isset( $_POST['gamebox_publisher'] ) ) {
- update_post_meta( $post_id, 'gamebox_publisher', sanitize_text_field( $_POST['gamebox_publisher'] ) );
- }
- if ( isset( $_POST['gamebox_publisher_ru'] ) ) {
- update_post_meta( $post_id, 'gamebox_publisher_ru', sanitize_text_field( $_POST['gamebox_publisher_ru'] ) );
- }
- if ( isset( $_POST['gamebox_genres'] ) && ! empty( $_POST['gamebox_genres'] ) ) {
- update_post_meta( $post_id, 'gamebox_genres', implode( ",", $_POST['gamebox_genres'] ) );
- }
- if ( isset( $_POST['gamebox_mm'] ) && isset( $_POST['gamebox_dd'] ) && isset( $_POST['gamebox_yyyy'] ) ) {
- $unix_date = "";
- $mm = intval( $_POST['gamebox_mm'] );
- $dd = intval( $_POST['gamebox_dd'] );
- $yyyy = intval( $_POST['gamebox_yyyy'] );
- if ( ! empty( $dd ) && $dd < 32 && ! empty( $mm ) && $mm < 13 && ! empty( $yyyy ) && $yyyy > 1970 ) {
- $unix_date = mktime( 0, 0, 0, $mm, $dd, $yyyy );
- }
- if ( ! empty( $unix_date ) ) {
- update_post_meta( $post_id, 'gamebox_date', $unix_date );
- }
- }
- if ( isset( $_POST['gamebox_mm_ru'] ) && isset( $_POST['gamebox_dd_ru'] ) && isset( $_POST['gamebox_yyyy_ru'] ) ) {
- $unix_date = "";
- $mm = intval( $_POST['gamebox_mm_ru'] );
- $dd = intval( $_POST['gamebox_dd_ru'] );
- $yyyy = intval( $_POST['gamebox_yyyy_ru'] );
- if ( ! empty( $dd ) && $dd < 32 && ! empty( $mm ) && $mm < 13 && ! empty( $yyyy ) && $yyyy > 1970 ) {
- $unix_date = mktime( 0, 0, 0, $mm, $dd, $yyyy );
- }
- if ( ! empty( $unix_date ) ) {
- update_post_meta( $post_id, 'gamebox_date_ru', $unix_date );
- }
- }
- if ( isset( $_POST['gamebox_platforms'] ) && ! empty( $_POST['gamebox_platforms'] ) ) {
- //сохраняем список платформ
- update_post_meta( $post_id, 'gamebox_platforms', implode( ",", $_POST['gamebox_platforms'] ) );
- //сохраняем список дат для платформ
- foreach ( (array) $_POST['gamebox_platforms'] as $_platform_key => $_platform_id ) {
- $mm = intval( $_POST['gamebox_platform_mm'][ $_platform_id ] );
- $dd = intval( $_POST['gamebox_platform_dd'][ $_platform_id ] );
- $yyyy = intval( $_POST['gamebox_platform_yyyy'][ $_platform_id ] );
- if ( ! empty( $dd ) && $dd < 32 && ! empty( $mm ) && $mm < 13 && ! empty( $yyyy ) && $yyyy > 1970 ) {
- $result_data[ $_platform_id ] = mktime( 0, 0, 0, $mm, $dd, $yyyy );
- }
- }
- if ( ! empty( $result_data ) ) {
- update_post_meta( $post_id, 'gamebox_platforms_dates', $result_data );
- }
- }
- return $post_id;
- }
- }
- add_action( 'save_post', 'gamebox_save_postdata' );
- /*
- *
- * Genres List
- *
- * */
- /* Добавляем в меню */
- if ( ! function_exists( 'register_genres_options_page' ) ) {
- function register_genres_options_page() {
- add_submenu_page( 'edit.php', __( 'Genres', 'gamebox' ), __( 'Genres', 'gamebox' ), 'manage_options', 'genres', 'genres_options_callback' );
- }
- }
- add_action( 'admin_menu', 'register_genres_options_page' );
- /* HTML код блока */
- if ( ! function_exists( 'genres_options_callback' ) ) {
- function genres_options_callback() {
- //страница редактирования
- if ( ! empty( $_GET["action"] ) && $_GET["action"] == "edit_genre" ) {
- genres_edit_form();
- return;
- }
- //получаем данные
- $genres_data = get_genres_data();
- // контент страницы
- echo '<h2>' . __( "Genres", "gamebox" ) . '</h2>';
- echo '
- <div class="form-wrap" style="width: 500px;">
- <h3>' . __( "Add Genre", "gamebox" ) . '</h3>
- <form method="post">
- <div class="form-field">
- <label for="genre-name">' . __( "Name", "gamebox" ) . '</label>
- <input type="text" size="40" value="" id="genre-name" name="new_genre_name" style="width: 500px;">
- </div>
- <p class="submit">
- <input type="submit" value="' . __( "Add Genre", "gamebox" ) . '" class="button button-primary" id="submit" name="add_genre">
- </p>
- </form>
- </div>
- ';
- //вывод существующих
- if ( ! empty( $genres_data ) ) {
- echo '
- <table class="wp-list-table widefat fixed tags" style="width: 500px;">
- <thead>
- <tr>
- <th style="" class="manage-column column-name" id="name" scope="col">
- <span>' . __( "Name", "gamebox" ) . '</span>
- </th>
- </tr>
- </thead>
- <tbody data-wp-lists="list:tag" id="the-list">
- ';
- $i = 0;
- foreach ( (array) $genres_data as $_info ) {
- $alternate_class = $i % 2 == 0 ? "alternate" : "";
- echo '
- <tr class="' . $alternate_class . '" id="tag-3">
- <td class="name column-name">
- <strong>
- <a title="Edit" href="edit.php?page=genres&action=edit_genre&genre_id=' . $_info["id"] . '" class="row-title">
- ' . $_info["name"] . '
- </a>
- </strong>
- <br>
- <div class="row-actions">
- <span class="edit">
- <a href="edit.php?page=genres&action=edit_genre&genre_id=' . $_info["id"] . '">
- ' . __( "Edit", "gamebox" ) . '
- </a> |
- </span>
- <span class="delete">
- <a onclick="return confirm(\'Are you sure?\')" href="edit.php?page=genres&action=delete_genre&genre_id=' . $_info["id"] . '">
- ' . __( "Delete", "gamebox" ) . '
- </a>
- </span>
- </div>
- </td>
- </tr>
- ';
- $i ++;
- }
- echo '
- </tbody>
- </table>
- ';
- }
- return;
- }
- }
- /* HTML код блока редактирования */
- if ( ! function_exists( 'genres_edit_form' ) ) {
- function genres_edit_form() {
- $location = 'edit.php?page=genres';
- $genre_id = intval( $_GET["genre_id"] );
- if ( empty( $genre_id ) ) {
- wp_redirect( $location );
- }
- //получаем данные
- $genre_data = get_genres_data($genre_id);
- $genre_data = $genre_data[0];
- if ( empty( $genre_data ) ) {
- wp_redirect( $location );
- }
- echo '<h2>' . __( "Edit Genre", "gamebox" ) . '</h2>';
- echo '
- <div class="form-wrap" style="width: 500px;">
- <form method="post" action="edit.php?page=genres&action=update_genre&genre_id=' . $genre_data["id"] . '">
- <div class="form-field">
- <label for="genre-name">' . __( "Name", "gamebox" ) . '</label>
- <input type="text" size="40" value="' . $genre_data["name"] . '" id="genre-name" name="new_genre_name" style="width: 500px;">
- </div>
- <p class="submit">
- <input type="submit" value="' . __( "Update Genre", "gamebox" ) . '" class="button button-primary" id="submit" name="update_genre">
- </p>
- </form>
- </div>
- ';
- return;
- }
- }
- /* Проверка существования таблицы*/
- if ( ! function_exists( 'genres_check_tbl' ) ) {
- function genres_check_tbl() {
- global $wpdb;
- $table_name = $wpdb->prefix . "genres";
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
- $sql = "
- CREATE TABLE " . $table_name . " (
- id mediumint(9) NOT NULL AUTO_INCREMENT,
- name tinytext NOT NULL,
- UNIQUE KEY id (id)
- );";
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- dbDelta( $sql );
- }
- return true;
- }
- }
- /* Сохраняем данные */
- if ( ! function_exists( 'genres_edit' ) ) {
- function genres_edit() {
- global $wpdb;
- $location = 'edit.php?page=genres';
- $table_name = $wpdb->prefix . "genres";
- //проверяем таблицу
- genres_check_tbl();
- //ADD
- if ( isset( $_POST["add_genre"] ) && ! empty( $_POST["new_genre_name"] ) ) {
- $wpdb->insert(
- $table_name,
- array( 'name' => esc_sql( $_POST["new_genre_name"] ) )
- );
- }
- //DELETE
- if ( $_GET["action"] == "delete_genre" ) {
- $genre_id = intval( $_GET["genre_id"] );
- if ( ! empty( $genre_id ) ) {
- $wpdb->delete( $table_name, array( 'ID' => $genre_id ) );
- }
- wp_redirect( $location );
- }
- //UPDATE
- if ( $_GET["action"] == "update_genre" && ! empty( $_POST["new_genre_name"] ) ) {
- $genre_id = intval( $_GET["genre_id"] );
- if ( empty( $genre_id ) ) {
- wp_redirect( $location );
- }
- //обновляем данные
- $wpdb->update( $table_name,
- array( 'name' => esc_sql( $_POST["new_genre_name"] ) ),
- array( 'ID' => $genre_id ),
- array( '%s' ),
- array( '%d' )
- );
- wp_redirect( $location );
- }
- }
- }
- add_action( 'admin_menu', 'genres_edit' );
- /* Получаем данные */
- if ( ! function_exists( 'get_genres_data' ) ) {
- function get_genres_data($id = "") {
- global $wpdb;
- //проверяем таблицу
- genres_check_tbl();
- if(!empty($id)){
- $where_id = " AND id=".intval($id);
- }
- //получаем данные
- $genres_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "genres WHERE 1".$where_id, "ARRAY_A" );
- return $genres_data;
- }
- }
- /*
- *
- * Platforms List
- *
- * */
- /* Добавляем в меню */
- if ( ! function_exists( 'register_platforms_options_page' ) ) {
- function register_platforms_options_page() {
- add_submenu_page( 'edit.php', __( 'Platforms', 'gamebox' ), __( 'Platforms', 'gamebox' ), 'manage_options', 'platforms', 'platforms_options_callback' );
- }
- }
- add_action( 'admin_menu', 'register_platforms_options_page' );
- /* HTML код блока */
- if ( ! function_exists( 'platforms_options_callback' ) ) {
- function platforms_options_callback() {
- //страница редактирования
- if ( ! empty( $_GET["action"] ) && $_GET["action"] == "edit_platform" ) {
- platforms_edit_form();
- return;
- }
- //получаем данные
- $platforms_data = get_platforms_data();
- // контент страницы
- echo '<h2>' . __( "Platforms", "gamebox" ) . '</h2>';
- echo '
- <div class="form-wrap" style="width: 500px;">
- <h3>' . __( "Add Platform", "gamebox" ) . '</h3>
- <form method="post">
- <div class="form-field">
- <label for="platform-name">' . __( "Name", "gamebox" ) . '</label>
- <input type="text" size="40" value="" id="platform-name" name="new_platform_name" style="width: 500px;">
- </div>
- <p class="submit">
- <input type="submit" value="' . __( "Add Platform", "gamebox" ) . '" class="button button-primary" id="submit" name="add_platform">
- </p>
- </form>
- </div>
- ';
- //вывод существующих
- if ( ! empty( $platforms_data ) ) {
- echo '
- <table class="wp-list-table widefat fixed tags" style="width: 500px;">
- <thead>
- <tr>
- <th style="" class="manage-column column-name" id="name" scope="col">
- <span>' . __( "Name", "gamebox" ) . '</span>
- </th>
- </tr>
- </thead>
- <tbody data-wp-lists="list:tag" id="the-list">
- ';
- $i = 0;
- foreach ( (array) $platforms_data as $_info ) {
- $alternate_class = $i % 2 == 0 ? "alternate" : "";
- echo '
- <tr class="' . $alternate_class . '" id="tag-3">
- <td class="name column-name">
- <strong>
- <a title="Edit" href="edit.php?page=platforms&action=edit_platform&platform_id=' . $_info["id"] . '" class="row-title">
- ' . $_info["name"] . '
- </a>
- </strong>
- <br>
- <div class="row-actions">
- <span class="edit">
- <a href="edit.php?page=platforms&action=edit_platform&platform_id=' . $_info["id"] . '">
- ' . __( "Edit", "gamebox" ) . '
- </a> |
- </span>
- <span class="delete">
- <a onclick="return confirm(\'Are you sure?\')" href="edit.php?page=platforms&action=delete_platform&platform_id=' . $_info["id"] . '">
- ' . __( "Delete", "gamebox" ) . '
- </a>
- </span>
- </div>
- </td>
- </tr>
- ';
- $i ++;
- }
- echo '
- </tbody>
- </table>
- ';
- }
- return;
- }
- }
- /* HTML код блока редактирования */
- if ( ! function_exists( 'platforms_edit_form' ) ) {
- function platforms_edit_form() {
- $location = 'edit.php?page=platforms';
- $platform_id = intval( $_GET["platform_id"] );
- if ( empty( $platform_id ) ) {
- wp_redirect( $location );
- }
- //получаем данные
- $platform_data = get_platforms_data($platform_id);
- $platform_data = $platform_data[0];
- if ( empty( $platform_data ) ) {
- wp_redirect( $location );
- }
- echo '<h2>' . __( "Edit Platform", "gamebox" ) . '</h2>';
- echo '
- <div class="form-wrap" style="width: 500px;">
- <form method="post" action="edit.php?page=platforms&action=update_platform&platform_id=' . $platform_data["id"] . '">
- <div class="form-field">
- <label for="platform-name">' . __( "Name", "gamebox" ) . '</label>
- <input type="text" size="40" value="' . $platform_data["name"] . '" id="platform-name" name="new_platform_name" style="width: 500px;">
- </div>
- <p class="submit">
- <input type="submit" value="' . __( "Update Platform", "gamebox" ) . '" class="button button-primary" id="submit" name="update_platform">
- </p>
- </form>
- </div>
- ';
- return;
- }
- }
- /* Проверка существования таблицы*/
- if ( ! function_exists( 'platforms_check_tbl' ) ) {
- function platforms_check_tbl() {
- global $wpdb;
- $table_name = $wpdb->prefix . "platforms";
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
- $sql = "
- CREATE TABLE " . $table_name . " (
- id mediumint(9) NOT NULL AUTO_INCREMENT,
- name tinytext NOT NULL,
- UNIQUE KEY id (id)
- );";
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- dbDelta( $sql );
- }
- return true;
- }
- }
- /* Сохраняем данные */
- if ( ! function_exists( 'platforms_edit' ) ) {
- function platforms_edit() {
- global $wpdb;
- $location = 'edit.php?page=platforms';
- $table_name = $wpdb->prefix . "platforms";
- //проверяем таблицу
- platforms_check_tbl();
- //ADD
- if ( isset( $_POST["add_platform"] ) && ! empty( $_POST["new_platform_name"] ) ) {
- $wpdb->insert(
- $table_name,
- array( 'name' => esc_sql( $_POST["new_platform_name"] ) )
- );
- }
- //DELETE
- if ( $_GET["action"] == "delete_platform" ) {
- $platform_id = intval( $_GET["platform_id"] );
- if ( ! empty( $platform_id ) ) {
- $wpdb->delete( $table_name, array( 'ID' => $platform_id ) );
- }
- wp_redirect( $location );
- }
- //UPDATE
- if ( $_GET["action"] == "update_platform" && ! empty( $_POST["new_platform_name"] ) ) {
- $platform_id = intval( $_GET["platform_id"] );
- if ( empty( $platform_id ) ) {
- wp_redirect( $location );
- }
- //обновляем данные
- $wpdb->update( $table_name,
- array( 'name' => esc_sql( $_POST["new_platform_name"] ) ),
- array( 'ID' => $platform_id ),
- array( '%s' ),
- array( '%d' )
- );
- wp_redirect( $location );
- }
- }
- }
- add_action( 'admin_menu', 'platforms_edit' );
- /* Получаем данные */
- if ( ! function_exists( 'get_platforms_data' ) ) {
- function get_platforms_data($id = "") {
- global $wpdb;
- //проверяем таблицу
- platforms_check_tbl();
- if(!empty($id)){
- $where_id = " AND id=".intval($id);
- }
- //получаем данные
- $platforms_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "platforms WHERE 1".$where_id, "ARRAY_A" );
- return $platforms_data;
- }
- }
- /*
- *
- * Game Link
- *
- * */
- /* Добавляем блоки в основную колонку на страницах постов и пост. страниц */
- if ( ! function_exists( 'gamelink_add_custom_box' ) ) {
- function gamelink_add_custom_box() {
- $screens = array( 'post', 'page' );
- foreach ( $screens as $screen ) {
- add_meta_box( 'gamelink', __( "Linked to Game", 'gamelink' ), 'gamelink_meta_box_callback', $screen );
- }
- }
- }
- add_action( 'add_meta_boxes', 'gamelink_add_custom_box' );
- /* HTML код блока */
- if ( ! function_exists( 'gamelink_meta_box_callback' ) ) {
- function gamelink_meta_box_callback() {
- global $post;
- //получаем текущую категорию
- $cur_post = get_the_category( $post->ID );
- $cur_post = current( $cur_post );
- $cur_post_cat_id = $cur_post->cat_ID;
- //получаем список категорий игр
- $cats = gamelink_get_cats_list();
- if ( empty( $cur_post_cat_id ) ) {
- echo '<span>Current post with no category.</span>';
- return;
- }
- if ( in_array( $cur_post_cat_id, $cats ) ) {
- echo '<span>Current post is in the category of games.</span>';
- return;
- }
- // Используем nonce для верификации
- wp_nonce_field( plugin_basename( __FILE__ ), 'gamelink_noncename' );
- //получаем список игр
- $games = gamelink_get_games_list();
- $gamelink_value = get_post_meta( $post->ID, 'gamelink_parent_id', true );
- if ( empty( $games ) ) {
- return;
- }
- // Поля формы для введения данных
- echo '<label for="gamelink_parent_id">' . __( "Games", 'gamelink' ) . '</label> ';
- echo '
- <select id="gamelink_parent_id" name="gamelink_parent_id">
- <option value="0"> ' . __( "No", 'gamelink' ) . ' </option>
- ';
- foreach ( (array) $games as $_id => $_name ) {
- echo '<option value=" ' . $_id . ' " ' . ( $gamelink_value == $_id ? ' selected="selected" ' : ' ' ) . '> ' . $_name . ' </option>';
- }
- echo '
- </select>
- ';
- }
- }
- /* получаем список категорий */
- if ( ! function_exists( 'gamelink_get_cats_list' ) ) {
- function gamelink_get_cats_list() {
- $cats = array();
- //получаем список категорий
- $categories_info = get_categories(
- array(
- 'child_of' => 3, //игры
- 'hide_empty' => 0
- )
- );
- if ( empty( $categories_info ) ) {
- return $cats;
- }
- foreach ( (array) $categories_info as $_info ) {
- $cats[ $_info->term_id ] = $_info->term_id;
- }
- return $cats;
- }
- }
- /* получаем список игр */
- if ( ! function_exists( 'gamelink_get_games_list' ) ) {
- function gamelink_get_games_list() {
- $games = array();
- //получаем список категорий игр
- $cats = gamelink_get_cats_list();
- if ( empty( $cats ) ) {
- return $games;
- }
- //получаем список игр
- foreach ( (array) $cats as $_cat_id ) {
- $posts = get_posts( array( 'category' => $_cat_id ) );
- if ( ! empty( $posts ) ) {
- foreach ( (array) $posts as $_post_info ) {
- $games[ $_post_info->ID ] = $_post_info->post_title;
- }
- }
- }
- asort( $games );
- return $games;
- }
- }
- /* Сохраняем данные, когда пост сохраняется */
- if ( ! function_exists( 'gamelink_save_postdata' ) ) {
- function gamelink_save_postdata( $post_id ) {
- // проверяем nonce нашей страницы, потому что save_post может быть вызван с другого места.
- if ( ! wp_verify_nonce( $_POST['gamelink_noncename'], plugin_basename( __FILE__ ) ) ) {
- return $post_id;
- }
- // проверяем, если это автосохранение ничего не делаем с данными нашей формы.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // проверяем разрешено ли пользователю указывать эти данные
- if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Убедимся что поле установлено.
- if ( ! isset( $_POST['gamelink_parent_id'] ) ) {
- return $post_id;
- }
- // Все ОК.
- // Обновляем данные в базе данных.
- update_post_meta( $post_id, 'gamelink_parent_id', intval( $_POST['gamelink_parent_id'] ) );
- return $post_id;
- }
- }
- add_action( 'save_post', 'gamelink_save_postdata' );
- /* Получаем данные */
- if ( ! function_exists( 'get_gamelink_data' ) ) {
- function get_gamelink_data() {
- global $wpdb;
- global $post;
- $data = $wpdb->get_results( "SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key='gamelink_parent_id' AND meta_value=" . $post->ID, "ARRAY_A" );
- if ( ! empty( $data ) ) {
- foreach ( (array) $data as $_info ) {
- $result[] = $_info["post_id"];
- }
- }
- return $result;
- }
- }
- /*
- *
- * Approve by Jurist
- *
- * */
- /* Добавляем блоки в основную колонку на страницах постов и пост. страниц */
- if ( ! function_exists( 'jurist_custom_box' ) ) {
- function jurist_custom_box() {
- $screens = array( 'post', 'page' );
- foreach ( $screens as $screen ) {
- add_meta_box( 'jurist', __( "Jurist Box", 'jurist' ), 'jurist_meta_box_callback', $screen, 'side' );
- }
- }
- }
- add_action( 'add_meta_boxes', 'jurist_custom_box' );
- /* HTML код блока */
- if ( ! function_exists( 'jurist_meta_box_callback' ) ) {
- function jurist_meta_box_callback() {
- // Используем nonce для верификации
- wp_nonce_field( plugin_basename( __FILE__ ), 'jurist_noncename' );
- global $post;
- $jurist_value = get_post_meta( $post->ID, 'jurist_plugin_value', true );
- global $current_user;
- $user_roles = $current_user->roles;
- $user_role = array_shift($user_roles);
- if ($user_role !== "jurist") {
- if ( $jurist_value == "1" ) {
- echo '<span style="color: green; font-weight: bold;">Одобрено</span>';
- } else {
- echo '<span style="color: red; font-weight: bold;">Не одобрено</span>';
- }
- return;
- }
- // Поля формы для введения данных
- echo '<label for="jurist_plugin_value">' . __( "Ободрено: ", 'jurist' ) . '</label> ';
- echo '
- <select id="jurist_plugin_value" name="jurist_plugin_value">
- <option value="0" ' . ( $jurist_value == '0' ? ' selected="selected" ' : ' ' ) . '> Нет </option>
- <option value="1" ' . ( $jurist_value == '1' ? ' selected="selected" ' : ' ' ) . '> Да </option>
- </select>
- ';
- }
- }
- /* Сохраняем данные, когда пост сохраняется */
- if ( ! function_exists( 'jurist_save_postdata' ) ) {
- function jurist_save_postdata( $post_id ) {
- // проверяем nonce нашей страницы, потому что save_post может быть вызван с другого места.
- if ( ! wp_verify_nonce( $_POST['jurist_noncename'], plugin_basename( __FILE__ ) ) ) {
- return $post_id;
- }
- // проверяем, если это автосохранение ничего не делаем с данными нашей формы.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // проверяем разрешено ли пользователю указывать эти данные
- if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Убедимся что поле установлено.
- if ( ! isset( $_POST['jurist_plugin_value'] ) ) {
- return $post_id;
- }
- // Все ОК.
- // Обновляем данные в базе данных.
- update_post_meta( $post_id, 'jurist_plugin_value', intval( $_POST['jurist_plugin_value'] ) );
- return $post_id;
- }
- }
- add_action( 'save_post', 'jurist_save_postdata' );
- /* Показываем поле в списке постов */
- if ( ! function_exists( 'jurist_column' ) ) {
- function jurist_column( $cols ) {
- $cols['jurist_column'] = "Юрист";
- return $cols;
- }
- }
- add_filter( 'manage_posts_columns', 'jurist_column', 5 );
- if ( ! function_exists( 'display_jurist_column' ) ) {
- function display_jurist_column( $col, $id ) {
- if ( $col !== "jurist_column" ) {
- return;
- }
- $jurist_value = get_post_meta( $id, 'jurist_plugin_value', true );
- if ( $jurist_value == "1" ) {
- echo '<span style="color: green; font-weight: bold;">Да</span>';
- } else {
- echo '<span style="color: red; font-weight: bold;">Нет</span>';
- }
- }
- }
- add_action( 'manage_posts_custom_column', 'display_jurist_column', 5, 2 );
- function publication_confirm_message_function(){
- global $post;
- $jurist_value = get_post_meta( $post->ID, 'jurist_plugin_value', true );
- $corrector_value = get_post_meta( $post->ID, 'corrector_plugin_value', true );
- if ( $jurist_value == "1" && $corrector_value == "1") {
- return true;
- } elseif($jurist_value == "0") {
- $publication_confirm_message = 'Эта запись не одобрена Юристом. Вы хотите ее опубликовать? Если да, то нажмите OK, если нет, то нажмите ОТМЕНА.';
- echo '<script type="text/javascript"><!--
- var publish = document.getElementById("publish");
- if (publish !== null) publish.onclick = function(){
- return confirm("' . $publication_confirm_message . '");
- };
- // --></script>';
- } elseif($corrector_value == "0") {
- $publication_confirm_message = 'Эта запись не одобрена Корректором. Вы хотите ее опубликовать? Если да, то нажмите OK, если нет, то нажмите ОТМЕНА.';
- echo '<script type="text/javascript"><!--
- var publish = document.getElementById("publish");
- if (publish !== null) publish.onclick = function(){
- return confirm("' . $publication_confirm_message . '");
- };
- // --></script>';
- }
- return true;
- }
- add_action('admin_footer', 'publication_confirm_message_function');
- //..............................................................................................................................
- /*
- *
- * Approve by Corrector
- *
- * */
- /* Добавляем блоки в основную колонку на страницах постов и пост. страниц */
- if ( ! function_exists( 'corrector_custom_box' ) ) {
- function corrector_custom_box() {
- $screens = array( 'post', 'page' );
- foreach ( $screens as $screen ) {
- add_meta_box( 'corrector', __( "Corrector Box", 'corrector' ), 'corrector_meta_box_callback', $screen, 'side' );
- }
- }
- }
- add_action( 'add_meta_boxes', 'corrector_custom_box' );
- /* HTML код блока */
- if ( ! function_exists( 'corrector_meta_box_callback' ) ) {
- function corrector_meta_box_callback() {
- // Используем nonce для верификации
- wp_nonce_field( plugin_basename( __FILE__ ), 'corrector_noncename' );
- global $post;
- $corrector_value = get_post_meta( $post->ID, 'corrector_plugin_value', true );
- global $current_user;
- $user_roles = $current_user->roles;
- $user_role = array_shift($user_roles);
- if ($user_role !== "corrector") {
- if ( $corrector_value == "1" ) {
- echo '<span style="color: green; font-weight: bold;">Одобрено</span>';
- } else {
- echo '<span style="color: red; font-weight: bold;">Не одобрено</span>';
- }
- return;
- }
- // Поля формы для введения данных
- echo '<label for="corrector_plugin_value">' . __( "Ободрено: ", 'corrector' ) . '</label> ';
- echo '
- <select id="corrector_plugin_value" name="corrector_plugin_value">
- <option value="0" ' . ( $corrector_value == '0' ? ' selected="selected" ' : ' ' ) . '> Нет </option>
- <option value="1" ' . ( $corrector_value == '1' ? ' selected="selected" ' : ' ' ) . '> Да </option>
- </select>
- ';
- }
- }
- /* Сохраняем данные, когда пост сохраняется */
- if ( ! function_exists( 'corrector_save_postdata' ) ) {
- function corrector_save_postdata( $post_id ) {
- // проверяем nonce нашей страницы, потому что save_post может быть вызван с другого места.
- if ( ! wp_verify_nonce( $_POST['corrector_noncename'], plugin_basename( __FILE__ ) ) ) {
- return $post_id;
- }
- // проверяем, если это автосохранение ничего не делаем с данными нашей формы.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // проверяем разрешено ли пользователю указывать эти данные
- if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Убедимся что поле установлено.
- if ( ! isset( $_POST['corrector_plugin_value'] ) ) {
- return $post_id;
- }
- // Все ОК.
- // Обновляем данные в базе данных.
- update_post_meta( $post_id, 'corrector_plugin_value', intval( $_POST['corrector_plugin_value'] ) );
- return $post_id;
- }
- }
- add_action( 'save_post', 'corrector_save_postdata' );
- /* Показываем поле в списке постов */
- if ( ! function_exists( 'corrector_column' ) ) {
- function corrector_column( $cols ) {
- $cols['corrector_column'] = "Корректор";
- return $cols;
- }
- }
- add_filter( 'manage_posts_columns', 'corrector_column', 5 );
- if ( ! function_exists( 'display_corrector_column' ) ) {
- function display_corrector_column( $col, $id ) {
- if ( $col !== "corrector_column" ) {
- return;
- }
- $corrector_value = get_post_meta( $id, 'corrector_plugin_value', true );
- if ( $corrector_value == "1" ) {
- echo '<span style="color: green; font-weight: bold;">Да</span>';
- } else {
- echo '<span style="color: red; font-weight: bold;">Нет</span>';
- }
- }
- }
- add_action( 'manage_posts_custom_column', 'display_corrector_column', 5, 2 );
- //..............................................................................................................................
- /**
- * Popular posts tracking
- *
- * Tracks the number of logged out user views for a post in a custom field
- */
- if ( ! function_exists( 'base_track_popular_posts' ) ) {
- function base_track_popular_posts() {
- // Only run the process for single posts, pages and post types when the user is logged out
- if ( is_singular() ) {
- global $post;
- $custom_field = '_base_popular_posts_count';
- // Set/check session
- if ( !session_id() )
- session_start();
- // Only track a one view per post for a single visitor session to avoid duplications
- if ( !isset( $_SESSION["popular-posts-count-{$post->ID}"] ) ) {
- // Update view count
- $view_count = get_post_meta( $post->ID, $custom_field, true );
- $stored_count = ( isset($view_count) && !empty($view_count) ) ? ( intval($view_count) + 1 ) : 1;
- $update_meta = update_post_meta( $post->ID, $custom_field, $stored_count );
- // Check for errors
- if ( is_wp_error($update_meta) )
- error_log( $update_meta->get_error_message(), 0 );
- // Store session in "viewed" state
- $_SESSION["popular-posts-count-{$post->ID}"] = 1;
- }
- // Show view the count for testing purposes (add "?show_count=1" onto the URL)
- if ( isset($_GET['show_count']) && intval($_GET['show_count']) == 1 ) {
- echo '<p style="color:red; text-align:center; margin:1em 0;">';
- echo get_post_meta( $post->ID, $custom_field, true );
- echo ' views of this post</p>';
- }
- }
- }
- }
- add_action('wp_head', 'base_track_popular_posts');
- function diw_post_thumbnail_feeds($content) {
- global $post;
- if(has_post_thumbnail($post->ID)) {
- $content = '<div>' . get_the_post_thumbnail($post->ID,$size='thumbnail') . '</div>' . $content;
- }
- return $content;
- }
- add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
- add_filter('the_content_feed', 'diw_post_thumbnail_feeds');
- require_once 'function_add.php';
- /* Meta-box posts_in_the_top */
- class trueMetaBox {
- function __construct($options) {
- $this->options = $options;
- $this->prefix = $this->options['id'] .'_';
- add_action( 'add_meta_boxes', array( &$this, 'create' ) );
- add_action( 'save_post', array( &$this, 'save' ), 1, 2 );
- }
- function create() {
- foreach ($this->options['post'] as $post_type) {
- if (current_user_can( $this->options['cap'])) {
- add_meta_box($this->options['id'], $this->options['name'], array(&$this, 'fill'), $post_type, $this->options['pos'], $this->options['pri']);
- }
- }
- }
- function fill(){
- global $post; $p_i_d = $post->ID;
- wp_nonce_field( $this->options['id'], $this->options['id'].'_wpnonce', false, true );
- ?>
- <table class="form-table"><tbody><?php
- foreach ( $this->options['args'] as $param ) {
- if (current_user_can( $param['cap'])) {
- ?><tr><?php
- if(!$value = get_post_meta($post->ID, $this->prefix .$param['id'] , true)) $value = $param['std'];
- switch ( $param['type'] ) {
- case 'text':{ ?>
- <th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
- <td>
- <input name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>" value="<?php echo $value ?>" placeholder="<?php echo $param['placeholder'] ?>" class="regular-text" /><br />
- <span class="description"><?php echo $param['desc'] ?></span>
- </td>
- <?php
- break;
- }
- case 'textarea':{ ?>
- <th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
- <td>
- <textarea name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>" value="<?php echo $value ?>" placeholder="<?php echo $param['placeholder'] ?>" class="large-text" /><?php echo $value ?></textarea><br />
- <span class="description"><?php echo $param['desc'] ?></span>
- </td>
- <?php
- break;
- }
- case 'checkbox':{ ?>
- <th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
- <td>
- <label for="<?php echo $this->prefix .$param['id'] ?>"><input name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>"<?php echo ($value=='on') ? ' checked="checked"' : '' ?> />
- <?php echo $param['desc'] ?></label>
- </td>
- <?php
- break;
- }
- case 'select':{ ?>
- <th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
- <td>
- <label for="<?php echo $this->prefix .$param['id'] ?>">
- <select name="<?php echo $this->prefix .$param['id'] ?>" id="<?php echo $this->prefix .$param['id'] ?>"><?php
- $top_posts = get_posts( array(
- 'meta_key' => 'posts_post_top',
- 'meta_value' => array('2', '3', '4', '5', '6'),
- ) );
- foreach ($top_posts as $top_post){
- $top_post_meta = get_post_meta($top_post->ID, 'posts_post_top');
- $top_posts_meta[$top_post_meta[0]] = $top_post_meta[0];
- }
- foreach($param['args'] as $val=>$name){
- ?><option value="<?php echo $val ?>"<?php echo ( isset ($top_posts_meta[$val]) ) ? ' disabled="disabled"' : '' ?> <?php echo ( $value == $val ) ? ' selected="selected"' : '' ?>><?php echo $name ?></option><?php
- }
- ?></select></label><br />
- <span class="description"><?php echo $param['desc'] ?></span>
- </td>
- <?php
- break;
- }
- }
- ?></tr><?php
- }
- }
- ?></tbody></table><?php
- }
- function save($post_id, $post){
- if ( !wp_verify_nonce( $_POST[ $this->options['id'].'_wpnonce' ], $this->options['id'] ) ) return;
- if ( !current_user_can( 'edit_post', $post_id ) ) return;
- if ( !in_array($post->post_type, $this->options['post'])) return;
- foreach ( $this->options['args'] as $param ) {
- if ( current_user_can( $param['cap'] ) ) {
- if ( isset( $_POST[ $this->prefix . $param['id'] ] ) && trim( $_POST[ $this->prefix . $param['id'] ] ) ) {
- update_post_meta( $post_id, $this->prefix . $param['id'], trim($_POST[ $this->prefix . $param['id'] ]) );
- } else {
- delete_post_meta( $post_id, $this->prefix . $param['id'] );
- }
- }
- }
- }
- }
- function save($post_id, $post){
- if ( !wp_verify_nonce( $_POST[ $this->options['id'].'_wpnonce' ], $this->options['id'] ) ) return;
- if ( !current_user_can( 'edit_post', $post_id ) ) return;
- if ( !in_array($post->post_type, $this->options['post'])) return;
- foreach ( $this->options['args'] as $param ) {
- if ( current_user_can( $param['cap'] ) ) {
- if ( isset( $_POST[ $this->prefix . $param['id'] ] ) && trim( $_POST[ $this->prefix . $param['id'] ] ) ) {
- update_post_meta( $post_id, $this->prefix . $param['id'], trim($_POST[ $this->prefix . $param['id'] ]) );
- } else {
- delete_post_meta( $post_id, $this->prefix . $param['id'] );
- }
- }
- }
- }
- $options = array(
- array(
- 'id' => 'posts',
- 'name' => 'Вывод постов в ТОП',
- 'post' => array('post', 'page'),
- 'pos' => 'normal',
- 'pri' => 'high',
- 'cap' => 'edit_posts',
- 'args' => array(
- array(
- 'id' => 'post_top',
- 'title' => 'Вывод постов в топ',
- 'type' => 'select',
- //'desc' => 'пояснение к полю',
- 'cap' => 'edit_posts',
- 'args' => array(
- '1' => 'default',
- '2' => 'сверху слева',
- '3' => 'сверху справа',
- '4' => 'снизу слева',
- '5' => 'снизу по центру',
- '6' => 'снизу справа'
- )
- )
- )
- )
- );
- foreach ($options as $option) {
- $truemetabox = new trueMetaBox($option);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement