Example #1
0
/**
 * Funzione che salva il contenuto del meta box per la pagina di modifica/inserimento di una Ricetta.
 *
 * @param int $post_id L'ID della pagina che deve essere salvata.
 */
function gallery_save_corridore_meta_box($post_id)
{
    if (!isset($_POST['superba_corridore_meta_box_nonce'])) {
        return;
    }
    if (!wp_verify_nonce($_POST['superba_corridore_meta_box_nonce'], 'superba_corridore_meta_box')) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    if (isset($_POST['post_type'])) {
        if ('corridore' == $_POST['post_type']) {
            if (!current_user_can('edit_post', $post_id)) {
                return;
            }
        } else {
            return;
        }
    }
    $admin_template = thb_get_admin_template();
    if ($admin_template !== 'single-corridore.php') {
        return;
    }
    $names = array('anno' => "anno", 'link_strava' => "link_strava");
    foreach ($names as $key => $name) {
        if (!isset($_POST[$name])) {
            continue;
        }
        $value = sanitize_text_field($_POST[$name]);
        update_post_meta($post_id, $name, $value);
    }
}
Example #2
0
 function thb_layout_global_options_container()
 {
     $thb_container = new THB_MetaboxFieldsContainer('', 'layout_container');
     if (thb_check_template_config('core/layout', 'meta_options_subtitle')) {
         if (!empty($_POST) || !thb_text_startsWith(thb_get_admin_template(), 'single')) {
             $field = new THB_TextField('subtitle');
             $field->setLabel(__('Page subtitle', 'thb_text_domain'));
             $thb_container->addField($field);
         }
     }
     if (thb_check_template_config('core/layout', 'meta_options_pageheader_disable')) {
         $field = new THB_CheckBoxField('pageheader_disable');
         $field->setDefault(false);
         $field->setLabel(__('Disable page header', 'thb_text_domain'));
         $thb_container->addField($field);
     }
     if (thb_check_template_config('core/layout', 'meta_options_page_boxed')) {
         $field = new THB_CheckBoxField('page_boxed');
         $field->setDefault(false);
         $field->setLabel(__('Box the page content and sidebar', 'thb_text_domain'));
         $field->setHelp(__('Checking this option, the page content and sidebar will both have a color background.', 'thb_text_domain'));
         $thb_container->addField($field);
     }
     if (thb_check_template_config('core/layout', 'meta_options_gutter')) {
         $thb_field = new THB_YesNoField('gutter');
         $thb_field->setDefault(thb_config('core/layout', 'meta_options_gutter_default'));
         $thb_field->setLabel(__('Gutter', 'thb_text_domain'));
         $thb_container->addField($thb_field);
     }
     return $thb_container;
 }
Example #3
0
/**
 * Portfolio page templates options metabox
 */
function thb_add_portfolio_metabox()
{
    if (thb_portfolio_framework_check() && thb_portfolio_config('metabox') && thb_is_admin_template(thb_portfolio_config('templates'))) {
        $ajax = thb_portfolio_config('ajax');
        $grid = thb_portfolio_config('grid_templates');
        $grid_columns = thb_portfolio_config('grid_templates_columns');
        $thb_metabox = thb_theme()->getPostType('page')->getMetabox('layout');
        $thb_tab = $thb_metabox->createTab(__('Portfolio options', 'thb-portfolio'), 'portfolio_options');
        $thb_tab->setIcon('welcome-view-site');
        $thb_container = $thb_tab->createContainer('', 'portfolio_loop_container');
        if (!empty($grid)) {
            if (thb_is_admin_template($grid)) {
                $current_template = thb_get_admin_template();
                // if ( isset( $grid_columns[$current_template] ) ) {
                if (in_array($current_template, array_keys($grid_columns))) {
                    thb_grid_layout_add_fields($thb_container, $grid_columns[$current_template]);
                }
            }
        }
        $thb_container = $thb_tab->createContainer('Filtering & ordering', 'portfolio_filtering_container');
        $thb_field = new THB_QueryFilterField('works_query');
        $thb_field->addClass('full');
        $thb_field->setTaxonomies(thb_get_post_type_taxonomies('works'));
        if (thb_is_admin_template(thb_portfolio_config('pagination_disabled_templates'))) {
            $thb_field->setHideNum();
        }
        $thb_container->addField($thb_field);
        $thb_container = $thb_tab->getContainer('portfolio_loop_container');
        if (!empty($ajax)) {
            if (thb_is_admin_template($ajax)) {
                $thb_field = new THB_YesNoField('works_ajax_pagination');
                $thb_field->setLabel(__('Use AJAX pagination', 'thb-portfolio'));
                $thb_field->setHelp(__('If the page template supports this feature (e.g. its items are filterable), enabling AJAX pagination won\'t refresh your page while filtering through Portfolio items.', 'thb-portfolio'));
                $thb_container->addField($thb_field);
            }
        }
    }
}
Example #4
0
/**
 * Funzione che salva il contenuto del meta box per la pagina di modifica/inserimento di una Ricetta.
 *
 * @param int $post_id L'ID della pagina che deve essere salvata.
 */
function superba_save_gara_meta_box($post_id)
{
    if (!isset($_POST['superba_gara_meta_box_nonce'])) {
        return;
    }
    if (!wp_verify_nonce($_POST['superba_gara_meta_box_nonce'], 'superba_gara_meta_box')) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // wp_die(print_r($_POST));
    if (isset($_POST['post_type'])) {
        if ('gara' == $_POST['post_type']) {
            if (!current_user_can('edit_post', $post_id)) {
                return;
            }
        } else {
            return;
        }
    }
    $admin_template = thb_get_admin_template();
    if ($admin_template !== 'single-gara.php') {
        return;
    }
    $names = array('link_url' => "link_url", 'partecipanti' => "partecipanti", 'galleria' => "galleria", 'activities_id' => "activities_id");
    // OK, we're authenticated: we need to find and save the data
    $corridori = $_POST['corridori'];
    update_post_meta($post_id, 'corridori', $corridori);
    // Make sure the file array isn't empty
    if (!empty($_FILES['wp_custom_attachment']['name'])) {
        // Setup the array of supported file types. In this case, it's just PDF.
        $supported_types = array('application/gpx+xml', 'application/octet-stream');
        // Get the file type of the upload
        $uploaded_type = $_FILES['wp_custom_attachment']['type'];
        // Check if the type is supported. If not, throw an error.
        if (in_array($uploaded_type, $supported_types)) {
            // Use the WordPress API to upload the file
            $upload = wp_upload_bits($_FILES['wp_custom_attachment']['name'], null, file_get_contents($_FILES['wp_custom_attachment']['tmp_name']));
            if (isset($upload['error']) && $upload['error'] != 0) {
                wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
            } else {
                $post_meta = add_post_meta($post_id, 'wp_custom_attachment', $upload);
                $update_meta = update_post_meta($post_id, 'wp_custom_attachment', $upload);
            }
            // end if/else
        } else {
            wp_die("The file type that you've uploaded is not a GPX." . print_r($supported_types) . "=" . $uploaded_type);
        }
        // end if/else
    }
    // end if
    // Make sure the file array isn't empty
    if (!empty($_FILES['wp_custom_attachment_2']['name'])) {
        // Setup the array of supported file types. In this case, it's just PDF.
        $supported_types = array('application/gpx+xml', 'application/octet-stream');
        // Get the file type of the upload
        $uploaded_type = $_FILES['wp_custom_attachment_2']['type'];
        // Check if the type is supported. If not, throw an error.
        if (in_array($uploaded_type, $supported_types)) {
            // Use the WordPress API to upload the file
            $upload = wp_upload_bits($_FILES['wp_custom_attachment_2']['name'], null, file_get_contents($_FILES['wp_custom_attachment_2']['tmp_name']));
            if (isset($upload['error']) && $upload['error'] != 0) {
                wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
            } else {
                $post_meta = add_post_meta($post_id, 'wp_custom_attachment_2', $upload);
                $update_meta = update_post_meta($post_id, 'wp_custom_attachment_2', $upload);
            }
            // end if/else
        } else {
            wp_die("The file type that you've uploaded is not a GPX." . print_r($supported_types) . "=" . $uploaded_type);
        }
        // end if/else
    }
    // end if
    foreach ($names as $key => $name) {
        if (!isset($_POST[$name])) {
            continue;
        }
        if (!is_array($_POST[$name])) {
            $value = sanitize_text_field($_POST[$name]);
            update_post_meta($post_id, $name, $value);
        } else {
            unset($_POST[$name][0]);
            //wp_die(print_r($_POST[$name]));
            $value = sanitize_text_field(serialize($_POST[$name]));
            update_post_meta($post_id, $name, $value);
        }
    }
}
 /**
  * Check the page template.
  *
  * @param string $template The page template to be checked against.
  * @return string
  */
 function thb_is_admin_template($template)
 {
     if (is_string($template)) {
         if (empty($_POST) && is_admin()) {
             return $template == thb_get_admin_template();
         }
         return true;
     } elseif (is_array($template)) {
         foreach ($template as $t) {
             if (thb_is_admin_template($t)) {
                 return true;
             }
         }
     }
     return false;
 }