Example #1
0
/**
 * Saves the new settings in the database.
 * Accepts the POST request data.
 */
function amt_save_settings($post_payload)
{
    // Default Add-Meta-Tags Settings
    $default_options = amt_get_default_options();
    $add_meta_tags_opts = array();
    foreach ($default_options as $def_key => $def_value) {
        // **Always** use the ``settings_version`` from the defaults
        if ($def_key == 'settings_version') {
            $add_meta_tags_opts['settings_version'] = $def_value;
        } elseif (array_key_exists($def_key, $post_payload)) {
            // Validate and sanitize input before adding to 'add_meta_tags_opts'
            if ($def_key == 'site_description') {
                $add_meta_tags_opts[$def_key] = sanitize_text_field(amt_sanitize_description(stripslashes($post_payload[$def_key])));
            } elseif ($def_key == 'site_keywords') {
                // No placeholders here
                $add_meta_tags_opts[$def_key] = sanitize_text_field(amt_sanitize_keywords(stripslashes($post_payload[$def_key])));
            } elseif ($def_key == 'global_keywords') {
                // placeholder may exist here
                $add_meta_tags_opts[$def_key] = amt_sanitize_keywords(amt_revert_placeholders(sanitize_text_field(amt_convert_placeholders(stripslashes($post_payload[$def_key])))));
            } elseif ($def_key == 'site_wide_meta') {
                $add_meta_tags_opts[$def_key] = esc_textarea(wp_kses(stripslashes($post_payload[$def_key]), amt_get_allowed_html_kses()));
            } elseif ($def_key == 'copyright_url') {
                $add_meta_tags_opts[$def_key] = esc_url_raw(stripslashes($post_payload[$def_key]), array('http', 'https'));
            } elseif ($def_key == 'default_image_url') {
                $add_meta_tags_opts[$def_key] = amt_esc_id_or_url_notation(stripslashes($post_payload[$def_key]), array('http', 'https'));
            } elseif ($def_key == 'social_main_facebook_publisher_profile_url') {
                $add_meta_tags_opts[$def_key] = esc_url_raw(stripslashes($post_payload[$def_key]), array('http', 'https'));
            } elseif ($def_key == 'social_main_googleplus_publisher_profile_url') {
                $add_meta_tags_opts[$def_key] = esc_url_raw(stripslashes($post_payload[$def_key]), array('http', 'https'));
            } elseif ($def_key == 'author_profile_source') {
                $author_profile_source_value = sanitize_text_field(stripslashes($post_payload[$def_key]));
                if (!in_array($author_profile_source_value, array('default', 'frontpage', 'buddypress', 'url'))) {
                    $author_profile_source_value = 'default';
                }
                $add_meta_tags_opts[$def_key] = $author_profile_source_value;
            } elseif ($def_key == 'transient_cache_expiration') {
                $transient_cache_expiration_value = sanitize_text_field(stripslashes($post_payload[$def_key]));
                if (!is_numeric($transient_cache_expiration_value) || intval($transient_cache_expiration_value) < 0) {
                    $transient_cache_expiration_value = '0';
                }
                $add_meta_tags_opts[$def_key] = $transient_cache_expiration_value;
            } else {
                $add_meta_tags_opts[$def_key] = sanitize_text_field(stripslashes($post_payload[$def_key]));
            }
        } else {
            // The following settings have a default value of 1, so they can never be
            // deactivated, unless the following check takes place.
            if ($def_key == 'auto_description' || $def_key == 'auto_keywords' || $def_key == 'noindex_search_results' || $def_key == 'metabox_enable_description' || $def_key == 'metabox_enable_keywords' || $def_key == 'metabox_enable_title') {
                if (!isset($post_payload[$def_key])) {
                    $add_meta_tags_opts[$def_key] = "0";
                }
            } else {
                // Else save the default value in the db.
                $add_meta_tags_opts[$def_key] = $def_value;
            }
        }
    }
    // Finally update the Add-Meta-Tags options.
    update_option("add_meta_tags_opts", $add_meta_tags_opts);
    //var_dump($post_payload);
    //var_dump($add_meta_tags_opts);
    amt_show_info_msg(__('Add-Meta-Tags options saved', 'add-meta-tags'));
}
function amt_user_extra_fields_save($user_id)
{
    /* Verify the nonce before proceeding. */
    // Verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (!isset($_POST['amt_noncename']) || !wp_verify_nonce($_POST['amt_noncename'], plugin_basename(AMT_PLUGIN_FILE))) {
        return;
    }
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Global Metadata metabox permission check (can be user customized via filter).
    if (!current_user_can($metabox_permissions['global_metabox_capability'])) {
        return;
    }
    // Get the Add-Meta-Tags options.
    $options = amt_get_options();
    // Check if the current user has permission to edit the post.
    if (!current_user_can('edit_published_posts')) {
        return;
    }
    // OK, we're authenticated: we need to find and save the data
    //
    // Sanitize user input
    //
    // Full metatags - We allow only <meta> elements.
    if (isset($_POST['amt_custom_full_metatags'])) {
        $full_metatags_value = esc_textarea(wp_kses(stripslashes($_POST['amt_custom_full_metatags']), amt_get_allowed_html_kses()));
    }
    // Image URL
    if (isset($_POST['amt_custom_image_url'])) {
        $image_url_value = amt_esc_id_or_url_notation(stripslashes($_POST['amt_custom_image_url']));
    }
    // If a value has not been entered we try to delete existing data from the database
    // If the user has entered data, store it in the database.
    // Add-Meta-Tags custom field names
    $amt_full_metatags_field_name = '_amt_user_full_metatags';
    $amt_image_url_field_name = '_amt_user_image_url';
    // As an extra security measure, here we also check the user-defined per box
    // permissions before we save any data in the database.
    // per user profile full meta tags
    if ($options['metabox_user_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['user_full_metatags_box_capability'])) {
        if (empty($full_metatags_value)) {
            delete_user_meta($user_id, $amt_full_metatags_field_name);
        } else {
            update_user_meta($user_id, $amt_full_metatags_field_name, $full_metatags_value);
        }
    }
    // Image URL
    if ($options['metabox_user_enable_image_url'] == '1' && current_user_can($metabox_permissions['user_image_url_box_capability'])) {
        if (empty($image_url_value)) {
            delete_user_meta($user_id, $amt_image_url_field_name);
        } else {
            update_user_meta($user_id, $amt_image_url_field_name, $image_url_value);
        }
    }
}
Example #3
0
function amt_get_term_image_info($size = 'thumbnail', $term_id = null)
{
    // Initial checks
    if (empty($term_id)) {
        if (is_category() || is_tag() || is_tax()) {
            // The post object is the term object
            $post = amt_get_queried_object();
            if (!isset($post->term_id)) {
                return false;
            }
            $term_id = $post->term_id;
        } else {
            return false;
        }
    } elseif (!is_numeric($term_id)) {
        return false;
    }
    // Get data from Custom Field
    $custom_image_url_value = amt_get_term_meta_image_url($term_id);
    // Get image data
    $image_data = amt_get_image_data(amt_esc_id_or_url_notation(stripslashes($custom_image_url_value)));
    // Construct image info array
    $image_info = array('url' => null, 'width' => null, 'height' => null);
    if (is_numeric($image_data['id'])) {
        $main_size_meta = wp_get_attachment_image_src($image_data['id'], $size);
        if (empty($main_size_meta)) {
            return false;
        }
        $image_info['url'] = $main_size_meta[0];
        $image_info['width'] = $main_size_meta[1];
        $image_info['height'] = $main_size_meta[2];
    } elseif (!is_null($image_data['url'])) {
        $image_info['url'] = $main_size_meta[0];
        $image_info['width'] = $main_size_meta[1];
        $image_info['height'] = $main_size_meta[2];
    } else {
        return false;
    }
    return $image_info;
}