Ejemplo n.º 1
0
/**
 * Create HiveQueen options and set the default values.
 *
 * @since 0.0.1
 *
 * @global hqdb $hqdb HiveQueen database abstraction object.
 * @global int  $hq_db_version
 * @global int  $hq_current_db_version
 */
function populate_options()
{
    global $hqdb, $hq_db_version, $hq_current_db_version;
    $guessurl = hq_guess_url();
    /**
     * Fires before creating HiveQueen options and populating their default values.
     *
     * @since 0.0.1
     */
    do_action('populate_options');
    if (ini_get('safe_mode')) {
        // Safe mode can break mkdir() so use a flat structure by default.
        $uploads_use_yearmonth_folders = 0;
    } else {
        $uploads_use_yearmonth_folders = 1;
    }
    $template = HQ_DEFAULT_THEME;
    // If default theme is a child theme, we need to get its template
    $theme = hq_get_theme($template);
    if (!$theme->errors()) {
        $template = $theme->get_template();
    }
    $timezone_string = '';
    $gmt_offset = 0;
    /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
    	   or a valid timezone string (America/New_York). See http://us3.php.net/manual/en/timezones.php
    	   for all timezone strings supported by PHP.
    	*/
    $offset_or_tz = _x('0', 'default GMT offset or timezone string');
    if (is_numeric($offset_or_tz)) {
        $gmt_offset = $offset_or_tz;
    } elseif ($offset_or_tz && in_array($offset_or_tz, timezone_identifiers_list())) {
        $timezone_string = $offset_or_tz;
    }
    $options = array('siteurl' => $guessurl, 'home' => $guessurl, 'blogname' => __('My Site'), 'blogdescription' => __('Just another HiveQueen site'), 'users_can_register' => 0, 'admin_email' => '*****@*****.**', 'start_of_week' => _x('1', 'start of week'), 'use_balanceTags' => 0, 'use_smilies' => 1, 'require_name_email' => 1, 'comments_notify' => 1, 'posts_per_rss' => 10, 'rss_use_excerpt' => 0, 'mailserver_url' => 'mail.example.com', 'mailserver_login' => '*****@*****.**', 'mailserver_pass' => 'password', 'mailserver_port' => 110, 'default_category' => 1, 'default_comment_status' => 'open', 'default_ping_status' => 'open', 'default_pingback_flag' => 1, 'posts_per_page' => 10, 'date_format' => __('F j, Y'), 'time_format' => __('g:i a'), 'links_updated_date_format' => __('F j, Y g:i a'), 'comment_moderation' => 0, 'moderation_notify' => 1, 'permalink_structure' => '', 'gzipcompression' => 0, 'hack_file' => 0, 'blog_charset' => 'UTF-8', 'moderation_keys' => '', 'active_plugins' => array(), 'category_base' => '', 'ping_sites' => 'http://rpc.pingomatic.com/', 'advanced_edit' => 0, 'comment_max_links' => 2, 'gmt_offset' => $gmt_offset, 'default_email_category' => 1, 'recently_edited' => '', 'template' => $template, 'stylesheet' => HQ_DEFAULT_THEME, 'comment_whitelist' => 1, 'blacklist_keys' => '', 'comment_registration' => 0, 'html_type' => 'text/html', 'use_trackback' => 0, 'default_role' => 'subscriber', 'db_version' => $hq_db_version, 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, 'upload_path' => '', 'blog_public' => '1', 'default_link_category' => 2, 'show_on_front' => 'posts', 'tag_base' => '', 'show_avatars' => '1', 'avatar_rating' => 'G', 'upload_url_path' => '', 'thumbnail_size_w' => 150, 'thumbnail_size_h' => 150, 'thumbnail_crop' => 1, 'medium_size_w' => 300, 'medium_size_h' => 300, 'avatar_default' => 'mystery', 'large_size_w' => 1024, 'large_size_h' => 1024, 'image_default_link_type' => 'file', 'image_default_size' => '', 'image_default_align' => '', 'close_comments_for_old_posts' => 0, 'close_comments_days_old' => 14, 'thread_comments' => 1, 'thread_comments_depth' => 5, 'page_comments' => 0, 'comments_per_page' => 50, 'default_comments_page' => 'newest', 'comment_order' => 'asc', 'sticky_posts' => array(), 'widget_categories' => array(), 'widget_text' => array(), 'widget_rss' => array(), 'uninstall_plugins' => array(), 'timezone_string' => $timezone_string, 'page_for_posts' => 0, 'page_on_front' => 0, 'default_post_format' => 0, 'link_manager_enabled' => 0, 'finished_splitting_shared_terms' => 1);
    // 3.3
    //TODO: no multisite
    //if ( ! is_multisite() ) {
    $options['initial_db_version'] = !empty($hq_current_db_version) && $hq_current_db_version < $hq_db_version ? $hq_current_db_version : $hq_db_version;
    //}
    //TODO: no multisite
    //if ( is_multisite() ) {
    //	/* translators: blog tagline */
    //	$options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_current_site()->site_name );
    //	$options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/';
    //}
    // Set autoload to no for these options
    $fat_options = array('moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins');
    $keys = "'" . implode("', '", array_keys($options)) . "'";
    $existing_options = $hqdb->get_col("SELECT option_name FROM {$hqdb->options} WHERE option_name in ( {$keys} )");
    $insert = '';
    foreach ($options as $option => $value) {
        if (in_array($option, $existing_options)) {
            continue;
        }
        if (in_array($option, $fat_options)) {
            $autoload = 'no';
        } else {
            $autoload = 'yes';
        }
        if (is_array($value)) {
            $value = serialize($value);
        }
        if (!empty($insert)) {
            $insert .= ', ';
        }
        $insert .= $hqdb->prepare("(%s, %s, %s)", $option, $value, $autoload);
    }
    if (!empty($insert)) {
        $hqdb->query("INSERT INTO {$hqdb->options} (option_name, option_value, autoload) VALUES " . $insert);
    }
    // In case it is set, but blank, update "home".
    if (!__get_option('home')) {
        update_option('home', $guessurl);
    }
    // Delete unused options.
    $unusedoptions = array('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'links_recently_updated_time', 'links_recently_updated_prepend', 'links_recently_updated_append', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_hqnonce', '_hq_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins', 'can_compress_scripts', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page', 'hqorg_popular_tags', 'what_to_show', 'rss_language', 'language', 'enable_xmlrpc', 'enable_app', 'embed_autourls', 'default_post_edit_rows');
    foreach ($unusedoptions as $option) {
        delete_option($option);
    }
    // Delete obsolete magpie stuff.
    $hqdb->query("DELETE FROM {$hqdb->options} WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?\$'");
    /*
     * Deletes all expired transients. The multi-table delete syntax is used
     * to delete the transient record from table a, and the corresponding
     * transient_timeout record from table b.
     */
    $time = time();
    $sql = "DELETE a, b FROM {$hqdb->options} a, {$hqdb->options} b\n\t\tWHERE a.option_name LIKE %s\n\t\tAND a.option_name NOT LIKE %s\n\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\tAND b.option_value < %d";
    $hqdb->query($hqdb->prepare($sql, $hqdb->esc_like('_transient_') . '%', $hqdb->esc_like('_transient_timeout_') . '%', $time));
    //TODO: Goyo no multisite
    //if ( is_main_site() && is_main_network() ) {
    if (true) {
        $sql = "DELETE a, b FROM {$hqdb->options} a, {$hqdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )\n\t\t\tAND b.option_value < %d";
        $hqdb->query($hqdb->prepare($sql, $hqdb->esc_like('_site_transient_') . '%', $hqdb->esc_like('_site_transient_timeout_') . '%', $time));
    }
}
Ejemplo n.º 2
0
/**
 * Insert or update a post.
 *
 * If the $postarr parameter has 'ID' set to a value, then post will be updated.
 *
 * You can set the post date manually, by setting the values for 'post_date'
 * and 'post_date_gmt' keys. You can close the comments or open the comments by
 * setting the value for 'comment_status' key.
 *
 * @since 0.0.1
 * @since 0.0.1
 *
 * @see sanitize_post()
 * @global hqdb $hqdb HiveQueen database abstraction object.
 *
 * @param array $postarr {
 *     An array of elements that make up a post to update or insert.
 *
 *     @type int    $ID                    The post ID. If equal to something other than 0,
 *                                         the post with that ID will be updated. Default 0.
 *     @type int    $post_author           The ID of the user who added the post. Default is
 *                                         the current user ID.
 *     @type string $post_date             The date of the post. Default is the current time.
 *     @type string $post_date_gmt         The date of the post in the GMT timezone. Default is
 *                                         the value of `$post_date`.
 *     @type mixed  $post_content          The post content. Default empty.
 *     @type string $post_content_filtered The filtered post content. Default empty.
 *     @type string $post_title            The post title. Default empty.
 *     @type string $post_excerpt          The post excerpt. Default empty.
 *     @type string $post_status           The post status. Default 'draft'.
 *     @type string $post_type             The post type. Default 'post'.
 *     @type string $comment_status        Whether the post can accept comments. Accepts 'open' or 'closed'.
 *                                         Default is the value of 'default_comment_status' option.
 *     @type string $ping_status           Whether the post can accept pings. Accepts 'open' or 'closed'.
 *                                         Default is the value of 'default_ping_status' option.
 *     @type string $post_password         The password to access the post. Default empty.
 *     @type string $post_name             The post name. Default is the sanitized post title.
 *     @type string $to_ping               Space or carriage return-separated list of URLs to ping.
 *                                         Default empty.
 *     @type string $pinged                Space or carriage return-separated list of URLs that have
 *                                         been pinged. Default empty.
 *     @type string $post_modified         The date when the post was last modified. Default is
 *                                         the current time.
 *     @type string $post_modified_gmt     The date when the post was last modified in the GMT
 *                                         timezone. Default is the current time.
 *     @type int    $post_parent           Set this for the post it belongs to, if any. Default 0.
 *     @type int    $menu_order            The order the post should be displayed in. Default 0.
 *     @type string $post_mime_type        The mime type of the post. Default empty.
 *     @type string $guid                  Global Unique ID for referencing the post. Default empty.
 * }
 * @param bool  $hq_error Optional. Whether to allow return of HQ_Error on failure. Default false.
 * @return int|HQ_Error The post ID on success. The value 0 or HQ_Error on failure.
 */
function hq_insert_post($postarr, $hq_error = false)
{
    global $hqdb;
    $user_id = get_current_user_id();
    $defaults = array('post_author' => $user_id, 'post_content' => '', 'post_content_filtered' => '', 'post_title' => '', 'post_excerpt' => '', 'post_status' => 'draft', 'post_type' => 'post', 'comment_status' => '', 'ping_status' => '', 'post_password' => '', 'to_ping' => '', 'pinged' => '', 'post_parent' => 0, 'menu_order' => 0, 'guid' => '', 'import_id' => 0, 'context' => '');
    $postarr = hq_parse_args($postarr, $defaults);
    unset($postarr['filter']);
    $postarr = sanitize_post($postarr, 'db');
    // Are we updating or creating?
    $post_ID = 0;
    $update = false;
    $guid = $postarr['guid'];
    if (!empty($postarr['ID'])) {
        $update = true;
        // Get the post ID and GUID.
        $post_ID = $postarr['ID'];
        $post_before = get_post($post_ID);
        if (is_null($post_before)) {
            if ($hq_error) {
                return new HQ_Error('invalid_post', __('Invalid post ID.'));
            }
            return 0;
        }
        $guid = get_post_field('guid', $post_ID);
        $previous_status = get_post_field('post_status', $post_ID);
    } else {
        $previous_status = 'new';
    }
    $post_type = empty($postarr['post_type']) ? 'post' : $postarr['post_type'];
    $post_title = $postarr['post_title'];
    $post_content = $postarr['post_content'];
    $post_excerpt = $postarr['post_excerpt'];
    if (isset($postarr['post_name'])) {
        $post_name = $postarr['post_name'];
    }
    $maybe_empty = 'attachment' !== $post_type && !$post_content && !$post_title && !$post_excerpt && post_type_supports($post_type, 'editor') && post_type_supports($post_type, 'title') && post_type_supports($post_type, 'excerpt');
    /**
     * Filter whether the post should be considered "empty".
     *
     * The post is considered "empty" if both:
     * 1. The post type supports the title, editor, and excerpt fields
     * 2. The title, editor, and excerpt fields are all empty
     *
     * Returning a truthy value to the filter will effectively short-circuit
     * the new post being inserted, returning 0. If $hq_error is true, a HQ_Error
     * will be returned instead.
     *
     * @since 0.0.1
     *
     * @param bool  $maybe_empty Whether the post should be considered "empty".
     * @param array $postarr     Array of post data.
     */
    if (apply_filters('hq_insert_post_empty_content', $maybe_empty, $postarr)) {
        if ($hq_error) {
            return new HQ_Error('empty_content', __('Content, title, and excerpt are empty.'));
        } else {
            return 0;
        }
    }
    $post_status = empty($postarr['post_status']) ? 'draft' : $postarr['post_status'];
    if ('attachment' === $post_type && !in_array($post_status, array('inherit', 'private', 'trash'))) {
        $post_status = 'inherit';
    }
    if (!empty($postarr['post_category'])) {
        // Filter out empty terms.
        $post_category = array_filter($postarr['post_category']);
    }
    // Make sure we set a valid category.
    if (empty($post_category) || 0 == count($post_category) || !is_array($post_category)) {
        // 'post' requires at least one category.
        if ('post' == $post_type && 'auto-draft' != $post_status) {
            $post_category = array(get_option('default_category'));
        } else {
            $post_category = array();
        }
    }
    // Don't allow contributors to set the post slug for pending review posts.
    if ('pending' == $post_status && !current_user_can('publish_posts')) {
        $post_name = '';
    }
    /*
     * Create a valid post name. Drafts and pending posts are allowed to have
     * an empty post name.
     */
    if (empty($post_name)) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_name = sanitize_title($post_title);
        } else {
            $post_name = '';
        }
    } else {
        // On updates, we need to check to see if it's using the old, fixed sanitization context.
        $check_name = sanitize_title($post_name, '', 'old-save');
        if ($update && strtolower(urlencode($post_name)) == $check_name && get_post_field('post_name', $post_ID) == $check_name) {
            $post_name = $check_name;
        } else {
            // new post, or slug has changed.
            $post_name = sanitize_title($post_name);
        }
    }
    /*
     * If the post date is empty (due to having been new or a draft) and status
     * is not 'draft' or 'pending', set date to now.
     */
    if (empty($postarr['post_date']) || '0000-00-00 00:00:00' == $postarr['post_date']) {
        $post_date = current_time('mysql');
    } else {
        $post_date = $postarr['post_date'];
    }
    // Validate the date.
    $mm = substr($post_date, 5, 2);
    $jj = substr($post_date, 8, 2);
    $aa = substr($post_date, 0, 4);
    $valid_date = hq_checkdate($mm, $jj, $aa, $post_date);
    if (!$valid_date) {
        if ($hq_error) {
            return new HQ_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return 0;
        }
    }
    if (empty($postarr['post_date_gmt']) || '0000-00-00 00:00:00' == $postarr['post_date_gmt']) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_date_gmt = get_gmt_from_date($post_date);
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    } else {
        $post_date_gmt = $postarr['post_date_gmt'];
    }
    if ($update || '0000-00-00 00:00:00' == $post_date) {
        $post_modified = current_time('mysql');
        $post_modified_gmt = current_time('mysql', 1);
    } else {
        $post_modified = $post_date;
        $post_modified_gmt = $post_date_gmt;
    }
    if ('attachment' !== $post_type) {
        if ('publish' == $post_status) {
            $now = gmdate('Y-m-d H:i:59');
            if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) {
                $post_status = 'future';
            }
        } elseif ('future' == $post_status) {
            $now = gmdate('Y-m-d H:i:59');
            if (mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false)) {
                $post_status = 'publish';
            }
        }
    }
    // Comment status.
    if (empty($postarr['comment_status'])) {
        if ($update) {
            $comment_status = 'closed';
        } else {
            $comment_status = get_default_comment_status($post_type);
        }
    } else {
        $comment_status = $postarr['comment_status'];
    }
    // These variables are needed by compact() later.
    $post_content_filtered = $postarr['post_content_filtered'];
    $post_author = empty($postarr['post_author']) ? $user_id : $postarr['post_author'];
    $ping_status = empty($postarr['ping_status']) ? get_default_comment_status($post_type, 'pingback') : $postarr['ping_status'];
    $to_ping = isset($postarr['to_ping']) ? sanitize_trackback_urls($postarr['to_ping']) : '';
    $pinged = isset($postarr['pinged']) ? $postarr['pinged'] : '';
    $import_id = isset($postarr['import_id']) ? $postarr['import_id'] : 0;
    /*
     * The 'hq_insert_post_parent' filter expects all variables to be present.
     * Previously, these variables would have already been extracted
     */
    if (isset($postarr['menu_order'])) {
        $menu_order = (int) $postarr['menu_order'];
    } else {
        $menu_order = 0;
    }
    $post_password = isset($postarr['post_password']) ? $postarr['post_password'] : '';
    if ('private' == $post_status) {
        $post_password = '';
    }
    if (isset($postarr['post_parent'])) {
        $post_parent = (int) $postarr['post_parent'];
    } else {
        $post_parent = 0;
    }
    /**
     * Filter the post parent -- used to check for and prevent hierarchy loops.
     *
     * @since 0.0.1
     *
     * @param int   $post_parent Post parent ID.
     * @param int   $post_ID     Post ID.
     * @param array $new_postarr Array of parsed post data.
     * @param array $postarr     Array of sanitized, but otherwise unmodified post data.
     */
    $post_parent = apply_filters('hq_insert_post_parent', $post_parent, $post_ID, compact(array_keys($postarr)), $postarr);
    $post_name = hq_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
    // Don't unslash.
    $post_mime_type = isset($postarr['post_mime_type']) ? $postarr['post_mime_type'] : '';
    // Expected_slashed (everything!).
    $data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid');
    $emoji_fields = array('post_title', 'post_content', 'post_excerpt');
    foreach ($emoji_fields as $emoji_field) {
        if (isset($data[$emoji_field])) {
            $charset = $hqdb->get_col_charset($hqdb->posts, $emoji_field);
            if ('utf8' === $charset) {
                $data[$emoji_field] = hq_encode_emoji($data[$emoji_field]);
            }
        }
    }
    if ('attachment' === $post_type) {
        /**
         * Filter attachment post data before it is updated in or added to the database.
         *
         * @since 0.0.1
         *
         * @param array $data    An array of sanitized attachment post data.
         * @param array $postarr An array of unsanitized attachment post data.
         */
        $data = apply_filters('hq_insert_attachment_data', $data, $postarr);
    } else {
        /**
         * Filter slashed post data just before it is inserted into the database.
         *
         * @since 0.0.1
         *
         * @param array $data    An array of slashed post data.
         * @param array $postarr An array of sanitized, but otherwise unmodified post data.
         */
        $data = apply_filters('hq_insert_post_data', $data, $postarr);
    }
    $data = hq_unslash($data);
    $where = array('ID' => $post_ID);
    if ($update) {
        /**
         * Fires immediately before an existing post is updated in the database.
         *
         * @since 0.0.1
         *
         * @param int   $post_ID Post ID.
         * @param array $data    Array of unslashed post data.
         */
        do_action('pre_post_update', $post_ID, $data);
        if (false === $hqdb->update($hqdb->posts, $data, $where)) {
            if ($hq_error) {
                return new HQ_Error('db_update_error', __('Could not update post in the database'), $hqdb->last_error);
            } else {
                return 0;
            }
        }
    } else {
        // If there is a suggested ID, use it if not already present.
        if (!empty($import_id)) {
            $import_id = (int) $import_id;
            if (!$hqdb->get_var($hqdb->prepare("SELECT ID FROM {$hqdb->posts} WHERE ID = %d", $import_id))) {
                $data['ID'] = $import_id;
            }
        }
        if (false === $hqdb->insert($hqdb->posts, $data)) {
            if ($hq_error) {
                return new HQ_Error('db_insert_error', __('Could not insert post into the database'), $hqdb->last_error);
            } else {
                return 0;
            }
        }
        $post_ID = (int) $hqdb->insert_id;
        // Use the newly generated $post_ID.
        $where = array('ID' => $post_ID);
    }
    if (empty($data['post_name']) && !in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) {
        $data['post_name'] = hq_unique_post_slug(sanitize_title($data['post_title'], $post_ID), $post_ID, $data['post_status'], $post_type, $post_parent);
        $hqdb->update($hqdb->posts, array('post_name' => $data['post_name']), $where);
        clean_post_cache($post_ID);
    }
    if (is_object_in_taxonomy($post_type, 'category')) {
        hq_set_post_categories($post_ID, $post_category);
    }
    if (isset($postarr['tags_input']) && is_object_in_taxonomy($post_type, 'post_tag')) {
        hq_set_post_tags($post_ID, $postarr['tags_input']);
    }
    // New-style support for all custom taxonomies.
    if (!empty($postarr['tax_input'])) {
        foreach ($postarr['tax_input'] as $taxonomy => $tags) {
            $taxonomy_obj = get_taxonomy($taxonomy);
            // array = hierarchical, string = non-hierarchical.
            if (is_array($tags)) {
                $tags = array_filter($tags);
            }
            if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                hq_set_post_terms($post_ID, $tags, $taxonomy);
            }
        }
    }
    $current_guid = get_post_field('guid', $post_ID);
    // Set GUID.
    if (!$update && '' == $current_guid) {
        $hqdb->update($hqdb->posts, array('guid' => get_permalink($post_ID)), $where);
    }
    if ('attachment' === $postarr['post_type']) {
        if (!empty($postarr['file'])) {
            update_attached_file($post_ID, $postarr['file']);
        }
        if (!empty($postarr['context'])) {
            add_post_meta($post_ID, '_hq_attachment_context', $postarr['context'], true);
        }
    }
    //TODO: Goyo no cache
    //clean_post_cache( $post_ID );
    $post = get_post($post_ID);
    if (!empty($postarr['page_template']) && 'page' == $data['post_type']) {
        $post->page_template = $postarr['page_template'];
        $page_templates = hq_get_theme()->get_page_templates($post);
        if ('default' != $postarr['page_template'] && !isset($page_templates[$postarr['page_template']])) {
            if ($hq_error) {
                return new HQ_Error('invalid_page_template', __('The page template is invalid.'));
            }
            update_post_meta($post_ID, '_hq_page_template', 'default');
        } else {
            update_post_meta($post_ID, '_hq_page_template', $postarr['page_template']);
        }
    }
    if ('attachment' !== $postarr['post_type']) {
        hq_transition_post_status($data['post_status'], $previous_status, $post);
    } else {
        if ($update) {
            /**
             * Fires once an existing attachment has been updated.
             *
             * @since 0.0.1
             *
             * @param int $post_ID Attachment ID.
             */
            do_action('edit_attachment', $post_ID);
        } else {
            /**
             * Fires once an attachment has been added.
             *
             * @since 0.0.1
             *
             * @param int $post_ID Attachment ID.
             */
            do_action('add_attachment', $post_ID);
        }
        return $post_ID;
    }
    if ($update) {
        /**
         * Fires once an existing post has been updated.
         *
         * @since 0.0.1
         *
         * @param int     $post_ID Post ID.
         * @param HQ_Post $post    Post object.
         */
        do_action('edit_post', $post_ID, $post);
        $post_after = get_post($post_ID);
        /**
         * Fires once an existing post has been updated.
         *
         * @since 0.0.1
         *
         * @param int     $post_ID      Post ID.
         * @param HQ_Post $post_after   Post object following the update.
         * @param HQ_Post $post_before  Post object before the update.
         */
        do_action('post_updated', $post_ID, $post_after, $post_before);
    }
    /**
     * Fires once a post has been saved.
     *
     * The dynamic portion of the hook name, `$post->post_type`, refers to
     * the post type slug.
     *
     * @since 0.0.1
     *
     * @param int     $post_ID Post ID.
     * @param HQ_Post $post    Post object.
     * @param bool    $update  Whether this is an existing post being updated or not.
     */
    do_action("save_post_{$post->post_type}", $post_ID, $post, $update);
    /**
     * Fires once a post has been saved.
     *
     * @since 0.0.1
     *
     * @param int     $post_ID Post ID.
     * @param HQ_Post $post    Post object.
     * @param bool    $update  Whether this is an existing post being updated or not.
     */
    do_action('save_post', $post_ID, $post, $update);
    /**
     * Fires once a post has been saved.
     *
     * @since 0.0.1
     *
     * @param int     $post_ID Post ID.
     * @param HQ_Post $post    Post object.
     * @param bool    $update  Whether this is an existing post being updated or not.
     */
    do_action('hq_insert_post', $post_ID, $post, $update);
    return $post_ID;
}
Ejemplo n.º 3
0
/**
 * Checks if a theme has been changed and runs 'after_switch_theme' hook on the next HQ load
 *
 * @since 0.0.1
 */
function check_theme_switched()
{
    if ($stylesheet = get_option('theme_switched')) {
        $old_theme = hq_get_theme($stylesheet);
        // Prevent retrieve_widgets() from running since Customizer already called it up front
        if (get_option('theme_switched_via_customizer')) {
            remove_action('after_switch_theme', '_hq_sidebars_changed');
            update_option('theme_switched_via_customizer', false);
        }
        if ($old_theme->exists()) {
            /**
             * Fires on the first HQ load after a theme switch if the old theme still exists.
             *
             * This action fires multiple times and the parameters differs
             * according to the context, if the old theme exists or not.
             * If the old theme is missing, the parameter will be the slug
             * of the old theme.
             *
             * @since 0.0.1
             *
             * @param string   $old_name  Old theme name.
             * @param HQ_Theme $old_theme HQ_Theme instance of the old theme.
             */
            do_action('after_switch_theme', $old_theme->get('Name'), $old_theme);
        } else {
            /** This action is documented in hq-includes/theme.php */
            do_action('after_switch_theme', $stylesheet);
        }
        update_option('theme_switched', false);
    }
}
Ejemplo n.º 4
0
/**
 * Render the theme options page for Twenty Eleven.
 *
 * @since HiveQueen Theme 0.1
 */
function hivequeen_theme_options_render_page()
{
    ?>
	<div class="wrap">
		<?php 
    screen_icon();
    ?>
		<?php 
    $theme_name = function_exists('hq_get_theme') ? hq_get_theme() : get_current_theme();
    ?>
		<h2><?php 
    printf(__('%s Theme Options', 'hivequeen'), $theme_name);
    ?>
</h2>
		<?php 
    settings_errors();
    ?>

		<form method="post" action="options.php">
			<?php 
    settings_fields('hivequeen_options');
    do_settings_sections('theme_options');
    submit_button();
    ?>
		</form>
	</div>
	<?php 
}