-1, 'page_content' => 'after', 'sort_method' => 'date', 'sort_order' => 'DESC', 'paginate_galleries' => '1', 'images_per_page' => '60', 'default_gallery_thumb' => 'last', 'hide_style' => '0', 'disable_ajax' => '0', 'add_calendar' => '0', 'separate_galleries' => '0', 'show_month_galleries' => '0', 'version' => $twobc_image_gallery_version, ); add_action('plugins_loaded', 'twobc_image_gallery_plugins_loaded'); /** * Plugin bootstrap * * Define constants * * Load textdomain * * @action plugins_loaded */ function twobc_image_gallery_plugins_loaded() { //define constants for plugin use define('TWOBC_IMAGEGALLERY_URL', plugin_dir_url(__FILE__)); define('TWOBC_IMAGEGALLERY_TEXT_DOMAIN', 'TwoBCImageGallery'); load_plugin_textdomain(TWOBC_IMAGEGALLERY_TEXT_DOMAIN, false, basename(dirname(__FILE__)) . '/lang'); // handle install and upgrade global $twobc_image_gallery_version; global $twobc_image_gallery_default_values; $plugin_options = twobc_image_gallery_get_options(); // install check if ( empty($plugin_options) ) { // init with default values update_option('twobc_image_gallery_options', $twobc_image_gallery_default_values); $plugin_options = $twobc_image_gallery_default_values; } // upgrade check if ( $twobc_image_gallery_version != $plugin_options['version'] ) { // init any empty db fields to catch any new additions foreach ($twobc_image_gallery_default_values as $_name => $_value) { if ( !isset($plugin_options[$_name]) ) { $plugin_options[$_name] = $_value; } } // set the updated settings update_option('twobc_image_gallery_options', $plugin_options); } } add_action('admin_enqueue_scripts', 'twobc_image_gallery_admin_enqueue'); /** * Admin script enqueue functions - 2bc-image-gallery-admin.js * Adds Gallery Featured Image option * * @action admin_enqueue_scripts */ function twobc_image_gallery_admin_enqueue() { // only need to load JS on attachment pages global $typenow; if ( !empty($typenow) && 'attachment' == $typenow ) { wp_enqueue_media(); global $twobc_image_gallery_version; wp_register_script( 'twobc_galleries_js_admin', // handle TWOBC_IMAGEGALLERY_URL . 'includes/js/2bc-image-gallery-admin.js', // path array ('jquery'), // dependencies $twobc_image_gallery_version // version ); wp_localize_script( 'twobc_galleries_js_admin', // script handle 'meta_image', // variable name array ( // values to pass 'title' => __('Choose or Upload an Image', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'button' => __('Use this image', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); wp_enqueue_script('twobc_galleries_js_admin'); } } add_action('wp_enqueue_scripts', 'twobc_image_gallery_front_enqueue'); /** * Front script and CSS enqueue functions * * @action wp_enqueue_scripts */ function twobc_image_gallery_front_enqueue() { $plugin_options = twobc_image_gallery_get_options(); global $post; // scripts if ( is_a($post, 'WP_Post') && ( ( // media gallery page isset($plugin_options['gallery_page']) && -1 != $plugin_options['gallery_page'] && $post->ID == $plugin_options['gallery_page'] ) || ( // shortcode found in post content has_shortcode($post->post_content, '2bc_image_gallery') ) ) && ( // ajax is not disabled empty($plugin_options['disable_ajax']) || '1' != $plugin_options['disable_ajax'] ) ) { global $twobc_image_gallery_version; wp_register_script( 'twobc_galleries_js_front', // handle TWOBC_IMAGEGALLERY_URL . 'includes/js/2bc-image-gallery-front.js', // source array ('jquery'), // dependencies $twobc_image_gallery_version, // version true // load in footer ); // localize script $script_options = array ( 'gallery' => null, 'page_num' => 1, 'page_id' => get_the_ID(), 'sort_method' => esc_attr($plugin_options['sort_method']), 'sort_order' => esc_attr($plugin_options['sort_order']), 'paginate_galleries' => esc_attr($plugin_options['paginate_galleries']), 'images_per_page' => esc_attr($plugin_options['images_per_page']), 'separate_galleries' => esc_attr($plugin_options['separate_galleries']), 'show_months' => esc_attr($plugin_options['show_months']), 'parents' => '', ); wp_localize_script('twobc_galleries_js_front', 'script_options', $script_options); // localize for ajax $ajax_options = array ( 'ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('twobc_image_gallery_ajax'), ); wp_localize_script('twobc_galleries_js_front', 'ajax_object', $ajax_options); wp_enqueue_script('twobc_galleries_js_front'); wp_register_script( 'twobc_galleries_js_picomodal', // handle TWOBC_IMAGEGALLERY_URL . 'includes/js/2bc-image-gallery-picomodal.js', // source array ('jquery'), // dependencies $twobc_image_gallery_version // version ); wp_enqueue_script('twobc_galleries_js_picomodal'); } // styles wp_register_style( 'twobc_galleries_css_core', // handle TWOBC_IMAGEGALLERY_URL . 'includes/css/2bc-image-gallery-core.css' // url source ); wp_enqueue_style('twobc_galleries_css_core'); // cosmetic style if ( empty($plugin_options['hide_style']) || '1' != $plugin_options['hide_style'] ) { wp_register_style( 'twobc_galleries_css_cosmetic', // handle TWOBC_IMAGEGALLERY_URL . 'includes/css/2bc-image-gallery-cosmetic.css' // url source ); wp_enqueue_style('twobc_galleries_css_cosmetic'); } } /***********************/ /*** CUSTOM TAXONOMY ***/ /***********************/ add_action('init', 'twobc_image_gallery_register_taxonomy'); /** * Register custom taxonomy - twobc_img_galleries * * @action init * * @see register_taxonomy() */ function twobc_image_gallery_register_taxonomy() { $tax_galleries_labels = apply_filters( 'twobc_image_gallery_tax_labels', // filter name array( // filter argument 'name' => _x('Galleries', 'taxonomy general name', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'singular_name' => _x('Gallery', 'taxonomy singular name', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'menu_name' => __('Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'search_items' => __('Search Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'all_items' => __('All Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'edit_item' => __('Edit Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'view_item' => __('View Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'update_item' => __('Update Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'add_new_item' => __('Add New Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'new_item_name' => __('New Gallery Name', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'popular_items' => __('Popular Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // non-hierarchical only 'separate_items_with_commas' => __('Separate galleries with commas', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // non-hierarchical only 'add_or_remove_items' => __('Add or remove galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // JS disabled, non-hierarchical only 'choose_from_most_used' => __('Choose from the most used galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'not_found' => __('No galleries found', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); $tax_galleries_args = apply_filters( 'twobc_image_gallery_tax_args', // filter name array( // filter argument 'hierarchical' => false, 'labels' => $tax_galleries_labels, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_generic_term_count', 'query_var' => true, 'rewrite' => false, 'sort' => false, ) ); register_taxonomy('twobc_img_galleries', array('attachment'), $tax_galleries_args); } /******************/ /*** ADMIN PAGE ***/ /******************/ add_action('admin_menu', 'twobc_image_gallery_settings_menu'); /** * Add 2BC Image Gallery options page * * @action admin_menu */ function twobc_image_gallery_settings_menu() { add_options_page( __('2BC Image Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // page title __('2BC Image Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // menu title 'manage_options', // capability required 'twobc_imagegallery', // page slug 'twobc_image_gallery_settings_page_cb' // display callback ); } add_action('admin_init', 'twobc_image_gallery_admin_init'); /** * Register all plugin options on settings page * * @action admin_init */ function twobc_image_gallery_admin_init() { // admin menu and pages register_setting( 'twobc_image_gallery_options', // option group name, declared with settings_fields() 'twobc_image_gallery_options', // option name, best to set same as group name 'twobc_image_gallery_options_sanitize_cb' // sanitization callback ); // SECTION - GENERAL $section = 'general'; add_settings_section( 'twobc_image_gallery_options_' . $section, // section HTML id __('Gallery Options', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // section title 'twobc_image_gallery_options_general_cb', // display callback 'twobc_imagegallery' // page to display on ); // Gallery Page $field = 'gallery_page'; $current_pages_args = array( 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'page', ); // get all current pages to populate dropdown $gallery_page_options = array ( __('Select a page…', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => '-1' ); $current_pages = get_posts($current_pages_args); if (!empty($current_pages) & !is_wp_error($current_pages)) { foreach ($current_pages as $page_obj) { $gallery_page_options[sanitize_text_field($page_obj->post_title . ' - ID: ' . $page_obj->ID)] = $page_obj->ID; } } add_settings_field( $field, // field HTML id __('Gallery Page', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_dropdown', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Select a page to display galleries on. The shortcode [2bc_image_gallery] can be used for manual display instead of setting a page here.', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'options' => $gallery_page_options, ) ); // Gallery Page Content $field = 'page_content'; add_settings_field( $field, // field HTML id __('Page Content', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_radio', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Control how page content is handled on the Gallery Page', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'options' => array ( __('Before page content', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'before', __('Replace %%2bc_image_gallery%% template tag', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'templatetag', __('After page content', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'after', __('Replace all page content with gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'replace', ), ) ); // Sort Method $field = 'sort_method'; add_settings_field( $field, // field HTML id __('Sort Method', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_dropdown', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array( // additional arguments 'name' => $field, 'description' => __('Select how gallery images are sorted: by uploaded date, alphbetically by filename, or random', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'options' => array( __('Date uploaded', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'date', __('Filename', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'title', __('Random', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'rand', ), ) ); // Sort Order $field = 'sort_order'; add_settings_field( $field, // field HTML id __('Sort Order', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_dropdown', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Which direction to sort, ascending (1, 2, 3) or descending (9, 8, 7)', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'options' => array( __('Descending', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'desc', __('Ascending', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'asc', ), ) ); // Paginate Galleries $field = 'paginate_galleries'; add_settings_field( $field, // field HTML id __('Paginate Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Break up galleries into pages', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // Images Per Page $field = 'images_per_page'; add_settings_field( $field, // field HTML id __('Images Per Page', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_number', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('How many images to display per page, only applies if pagination is enabled', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // Default Gallery Thumb $field = 'default_gallery_thumb'; add_settings_field( $field, // field HTML id __('Gallery Thumb Source', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_dropdown', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('If the gallery does not have a custom thumbnail, decide how to generate one', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), 'options' => array( __('Last image added', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'last', __('First image added', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'first', __('Random', TWOBC_IMAGEGALLERY_TEXT_DOMAIN) => 'random', ), ) ); // Hide Style $field = 'hide_style'; add_settings_field( $field, // field HTML id __('Hide Default Stying', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Check to not load the default style sheet, and create the styling in the theme CSS instead', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // Disable AJAX $field = 'disable_ajax'; add_settings_field( $field, // field HTML id __('Disable AJAX', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Check to disable AJAX calls. Do this if galleries are not loading when clicked. This will mean that the page will refresh with the new content.', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // SECTION - DATE GALLERIES $section = 'calendar'; add_settings_section( 'twobc_image_gallery_options_' . $section, // section HTML id __('Calendar Based Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // section title 'twobc_image_gallery_options_general_cb', // display callback 'twobc_imagegallery' // page to display on ); // Add Calendar Galleries $field = 'add_calendar'; add_settings_field( $field, // field HTML id __('Add Calendar Based Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Add calendar galleries (i.e. January, 2012) to uploaded images', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // Separate Calendar Galleries $field = 'separate_galleries'; add_settings_field( $field, // field HTML id __('Separate Calendar Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Show calendar galleries in their own separate section', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); // Show Month Galleries $field = 'show_months'; add_settings_field( $field, // field HTML id __('Show Month Galleries', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // field title 'twobc_image_gallery_create_checkbox', // display callback 'twobc_imagegallery', // page to display on 'twobc_image_gallery_options_' . $section, // section to display in array ( // additional arguments 'name' => $field, 'description' => __('Display month-based galleries on the main page, only applies if Separate Calendar Galleries is checked', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), ) ); } /** * CSS for admin options page * * @return string */ function twobc_image_gallery_get_admin_css() { $output = ''; return $output; } /** * Javascript for admin options page * * @return string */ function twobc_image_gallery_get_admin_js() { $output = ''; return $output; } /** * 2BC Image Gallery options callback */ function twobc_image_gallery_settings_page_cb() { //must check that the user has the required capability if ( !current_user_can('manage_options' )) { wp_die(__('You do not have sufficient permissions to access this page.', TWOBC_IMAGEGALLERY_TEXT_DOMAIN)); } $image_gallery_admin_css = twobc_image_gallery_get_admin_css(); if ( !empty($image_gallery_admin_css) ) { echo ' '; } echo ' '; $image_gallery_js = twobc_image_gallery_get_admin_js(); if (!empty($image_gallery_js)) { echo ' '; } } /** * Options page header callback */ function twobc_image_gallery_options_general_cb() { // intentionally left blank } /** * Sanitize option values callback * * @param $saved_settings * * @return mixed */ function twobc_image_gallery_options_sanitize_cb($saved_settings) { $settings_errors = array ( 'updated' => false, 'error' => array (), ); $known_fields = array( 'gallery_page' => 'dropdown', 'page_content' => 'radio', 'sort_method' => 'dropdown', 'sort_order' => 'dropdown', 'paginate_galleries' => 'checkbox', 'images_per_page' => 'number', 'default_gallery_thumb' => 'dropdown', 'hide_style' => 'checkbox', 'disable_ajax' => 'checkbox', 'add_calendar' => 'checkbox', 'separate_galleries' => 'checkbox', 'show_months' => 'checkbox', ); foreach ($saved_settings as $setting_key => $setting_val) { // security checks - nonce, capability if ( isset($known_fields[$setting_key]) && check_admin_referer( 'twobc_image_gallery_options_nonce', // nonce action 'twobc_image_gallery_options_' . $setting_key // query arg, nonce name ) && current_user_can('manage_options') ) { switch ($known_fields[$setting_key]) { case 'checkbox' : $saved_settings[$setting_key] = '1'; $settings_errors['updated'] = true; break; case 'number' : if ( is_numeric($setting_val) ) { $saved_settings[$setting_key] = intval($setting_val); $settings_errors['updated'] = true; } else { unset($saved_settings[$setting_key]); } break; case 'dropdown' : case 'radio' : $saved_settings[$setting_key] = sanitize_text_field($setting_val); $settings_errors['updated'] = true; break; default : // unknown field type? Shouldn't happen, but unset to be safe unset($saved_settings[$setting_key]); } } else { // unknown field? unset to be safe unset($saved_settings[$setting_key]); } } // separate validation for un-checked checkboxes foreach ($known_fields as $field_name => $field_type) { if ( 'checkbox' == $field_type && !isset($saved_settings[$field_name]) ) { $saved_settings[$field_name] = '0'; $settings_errors['updated'] = true; } } // register errors if (!empty($settings_errors['errors']) && is_array($settings_errors['errors'])) { foreach ($settings_errors['errors'] as $error) { add_settings_error( 'twobc_image_gallery_options', // Slug title of the setting 'twobc_image_gallery_options_error', // Slug of error sprintf(__('%s', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), $error), // Error message 'error' // Type of error (**error** or **updated**) ); } } if (true === $settings_errors['updated']) { add_settings_error( 'twobc_image_gallery_options', // Slug title of the setting 'twobc_image_gallery_options_error', // Slug of error __('Settings saved.', TWOBC_IMAGEGALLERY_TEXT_DOMAIN), // Error message 'updated' // Type of error (**error** or **updated**) ); } // set plugin version number global $twobc_image_gallery_version; $saved_settings['version'] = $twobc_image_gallery_version; return $saved_settings; } /** * Create HTML checkbox for options page * * @param $args */ function twobc_image_gallery_create_checkbox($args) { $field_value = twobc_image_gallery_get_options(); $field_value = (isset($field_value[$args['name']]) && '1' == $field_value[$args['name']] ? '1' : null); // field nonce wp_nonce_field( 'twobc_image_gallery_options_nonce', // action 'twobc_image_gallery_options_' . $args['name'] // custom name ); echo '
'; echo ' '; echo '
'; if (!empty($args['description'])) { echo '

' . $args['description'] . '

'; } } /** * Create HTML dropdown for options page * * @param $args */ function twobc_image_gallery_create_dropdown($args) { $field_value = twobc_image_gallery_get_options(); $field_value = (isset($field_value[$args['name']]) ? sanitize_text_field($field_value[$args['name']]) : null); // field nonce wp_nonce_field( 'twobc_image_gallery_options_nonce', // action 'twobc_image_gallery_options_' . $args['name'] // custom name ); echo ' '; if (!empty($args['options'])) { foreach ($args['options'] as $opt_name => $opt_value) { echo ''; echo sanitize_text_field($opt_name); echo ' '; } } echo ' '; if (!empty($args['description'])) { echo '

' . $args['description'] . '

'; } } /** * Create HTML radio input for options page * * @param $args */ function twobc_image_gallery_create_radio($args) { $field_value = twobc_image_gallery_get_options(); $field_value = (isset($field_value[$args['name']]) ? sanitize_text_field($field_value[$args['name']]) : null); // field nonce wp_nonce_field( 'twobc_image_gallery_options_nonce', // action 'twobc_image_gallery_options_' . $args['name'] // custom name ); if ( !empty($args['options']) ) { if (!empty($args['description'])) { echo '

' . $args['description'] . '

'; } echo '
'; foreach ($args['options'] as $opt_name => $opt_value) { echo '
'; } echo '
'; } } /** * Create HTML number for options page * * @param $args */ function twobc_image_gallery_create_number($args) { $field_value = twobc_image_gallery_get_options(); $field_value = (isset($field_value[$args['name']]) ? intval($field_value[$args['name']]) : null); // field nonce wp_nonce_field( 'twobc_image_gallery_options_nonce', // action 'twobc_image_gallery_options_' . $args['name'] // custom name ); echo ' '; if (!empty($args['description'])) { echo '

' . $args['description'] . '

'; } } add_action('admin_notices', 'twobc_image_gallery_admin_notices'); /** * Add admin notice to 2BC Image Gallery page * * @action admin_notices */ function twobc_image_gallery_admin_notices() { $image_gallery_options = twobc_image_gallery_get_options(); global $post; $current_screen = get_current_screen(); if ( isset($image_gallery_options['gallery_page']) && 'page' == $current_screen->id && 'edit' == $current_screen->parent_base && $post->ID == $image_gallery_options['gallery_page'] ) { echo '

'; _e('This page is currently being used to display the 2BC Media Gallery', TWOBC_IMAGEGALLERY_TEXT_DOMAIN); echo '

'; } } /***************************/ /*** TAXONOMY ADMIN PAGE ***/ /***************************/ add_action('twobc_img_galleries_add_form_fields', 'twobc_image_gallery_taxonomy_fields_add', 10, 2); /** * Add custom fields to Add Gallery page - featured gallery image picker * * @action twobc_img_galleries_add_form_fields */ function twobc_image_gallery_taxonomy_fields_add() { echo '
'; echo ' '; echo ' '; echo '

'; _e('Choose or upload a picture to be the galleries featured image', TWOBC_IMAGEGALLERY_TEXT_DOMAIN); echo '

'; echo '
'; } add_action('twobc_img_galleries_edit_form_fields', 'twobc_image_gallery_taxonomy_fields_edit', 10, 2); /** * Add custom fields to Edit Gallery page - featured gallery image picker * * @param $term * * @action twobc_img_galleries_edit_form_fields */ function twobc_image_gallery_taxonomy_fields_edit($term) { // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_option( 'taxonomy_' . $term->term_id ); echo ' '; echo ' '; echo ' '; echo ' '; echo '

'; _e( 'Choose or upload a picture to be the galleries featured image', TWOBC_IMAGEGALLERY_TEXT_DOMAIN ); echo '

'; echo ' '; echo ' '; } add_action('edited_twobc_img_galleries', 'twobc_image_gallery_taxonomy_fields_save', 10, 2); add_action('created_twobc_img_galleries', 'twobc_image_gallery_taxonomy_fields_save', 10, 2); /** * Save custom fields on Gallery pages * * @param $term_id * * @action edited_twobc_img_galleries, created_twobc_img_galleries */ function twobc_image_gallery_taxonomy_fields_save($term_id) { if ( isset($_POST['twobc_img_galleries_meta']) ) { $term_meta = (get_option('taxonomy_' . $term_id)); $tax_keys = array_keys($_POST['twobc_img_galleries_meta']); foreach ($tax_keys as $a_key) { $term_meta[esc_attr($a_key)] = esc_attr($_POST['twobc_img_galleries_meta'][$a_key]); } // save the option array update_option('taxonomy_' . $term_id, $term_meta); } } add_filter('manage_edit-twobc_img_galleries_columns', 'twobc_image_gallery_taxonomy_columns'); /** * Set custom, sortable ID column on taxonomy page - add the custom column * * @param $columns * * @filter manage_edit-twobc_img_galleries_columns * * @return mixed */ function twobc_image_gallery_taxonomy_columns($columns) { $columns['id'] = __('ID', TWOBC_IMAGEGALLERY_TEXT_DOMAIN); return $columns; } add_action('manage_twobc_img_galleries_custom_column', 'twobc_image_gallery_taxonomy_id_column', 10, 3); /** * Set custom, sortable ID column on taxonomy page - display the custom column contents * * @param $value * @param $col_name * @param $id * * @action manage_twobc_img_galleries_custom_column * * @return int */ function twobc_image_gallery_taxonomy_id_column($value, $col_name, $id) { if ( 'id' == $col_name ) { return intval($id); } return null; } add_filter('manage_edit-twobc_img_galleries_sortable_columns', 'twobc_image_gallery_taxonomy_sortable_columns'); /** * Set custom, sortable ID column on taxonomy page - set custom column as sortable * * @param $columns * * @filter manage_edit-twobc_img_galleries_sortable_columns * * @return mixed */ function twobc_image_gallery_taxonomy_sortable_columns($columns) { $columns['id'] = 'id'; return $columns; } /***************/ /*** DISPLAY ***/ /***************/ add_filter('the_content', 'twobc_image_gallery_page_filter'); /** * Filter content of Image Gallery page to display galleries * * @param $content * * @filter the_content * * @return string */ function twobc_image_gallery_page_filter($content) { $plugin_options = twobc_image_gallery_get_options(); if ( isset($plugin_options['gallery_page']) && '-1' != $plugin_options['gallery_page'] && is_page($plugin_options['gallery_page']) && isset($plugin_options['page_content']) ) { switch ($plugin_options['page_content']) { // before case 'before' : $content = twobc_image_gallery_get_display() . $content; break; // replace case 'replace' : $content = twobc_image_gallery_get_display(); break; // templatetag - %%2bc_image_gallery%% case 'templatetag' : $limit = 1; $content = str_replace( '%%2bc_image_gallery%%', // needle twobc_image_gallery_get_display(), // replacement $content, // haystack $limit // limit ); break; // after // default case 'after' : default : $content .= twobc_image_gallery_get_display(); } } return $content; } /** * Get gallery display HTML * * @param array $args * * @return string * * @uses twobc_image_gallery_get_thumb_html() */ function twobc_image_gallery_get_display($args = array()) { $output = ''; // get the plugin options $image_gallery_options = twobc_image_gallery_get_options(); $default_args = array( 'display_gallery' => '', 'page_num' => '1', 'page_id' => get_the_ID(), 'parents' => '', 'galleries' => '', 'page_content' => $image_gallery_options['page_content'], 'sort_method' => $image_gallery_options['sort_method'], 'sort_order' => $image_gallery_options['sort_order'], 'paginate_galleries' => $image_gallery_options['paginate_galleries'], 'images_per_page' => $image_gallery_options['images_per_page'], 'default_gallery_thumb' => $image_gallery_options['default_gallery_thumb'], 'separate_galleries' => $image_gallery_options['separate_galleries'], 'show_months' => $image_gallery_options['show_months'], 'back_button' => '', 'noajax' => '', ); // set args over-ride flag $args_override = false; if ( !empty($args) ) { $args_override = $args; } // set GET over-ride flag if ( !empty($_GET) ) { foreach ($_GET as $_get_name => $_get_value) { $get_name = esc_attr($_get_name); $get_value = esc_attr($_get_value); if ( isset($default_args[$get_name]) ) { $args_override[$get_name] = $get_value; $args[$get_name] = $get_value; } } } $args = wp_parse_args($args, $default_args); // optional nested galleries - build array from args if present $parent_galleries = array (); if ( !empty($args['parents']) && is_string($args['parents']) ) { $parent_galleries = explode(',', $args['parents']); if ( 1 == count($parent_galleries )) { $parent_galleries = reset($parent_galleries); } } // shortcut to display a gallery - for non-JS cases if ( isset($args['display_gallery']) && is_numeric($args['display_gallery']) ) { $shortcut_args = array( 'page_id' => get_the_ID(), 'term_id' => $args['display_gallery'], 'page_num' => $args['page_num'], 'sort_order' => $args['sort_order'], 'sort_method' => $args['sort_method'], 'paginate_galleries' => $args['paginate_galleries'], 'images_per_page' => $args['images_per_page'], 'back_button' => $args['back_button'], ); $shortcut_args['term_title'] = get_term($shortcut_args['term_id'], 'twobc_img_galleries'); $shortcut_args['term_title'] = $shortcut_args['term_title']->name; $shortcut_args['parents'] = $args['parents']; $output = ' '; return $output; } // find out if we were passed galleries to display $optional_galleries = array(); if ( !empty($args['galleries']) && is_string($args['galleries']) ) { $optional_galleries = explode(',', $args['galleries']); if ( !empty($optional_galleries) && is_array($optional_galleries) ) { foreach ($optional_galleries as &$gallery_id) { $gallery_id = esc_attr(trim($gallery_id)); } } } $get_terms_args = array( 'cache_domain' => 'twobc_image_gallery', ); if ( !empty($optional_galleries) ) { foreach ($optional_galleries as $a_term_id) { $get_terms_args['include'][] = $a_term_id; } } // get all current terms $term_array = get_terms('twobc_img_galleries', $get_terms_args); // Begin display $output .= '