/**
  * Saves all selected primary terms
  *
  * @param int $post_ID Post ID to save primary terms for.
  */
 public function save_primary_terms($post_ID)
 {
     // Bail if this is a multisite installation and the site has been switched.
     if (is_multisite() && ms_is_switched()) {
         return;
     }
     $taxonomies = $this->get_primary_term_taxonomies($post_ID);
     foreach ($taxonomies as $taxonomy) {
         $this->save_primary_term($post_ID, $taxonomy);
     }
 }
	function tearDown() {
		global $wpdb, $wp_query, $post;
		$wpdb->query( 'ROLLBACK' );
		if ( is_multisite() ) {
			while ( ms_is_switched() ) {
				restore_current_blog();
			}
		}
		$wp_query = new WP_Query();
		$post = null;
		remove_theme_support( 'html5' );
		remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
		remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
		remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
		$this->_restore_hooks();
		wp_set_current_user( 0 );
	}
	function test_switch_restore_blog() {
		global $_wp_switched_stack, $wpdb;

		$this->assertEquals( array(), $_wp_switched_stack );
		$this->assertFalse( ms_is_switched() );
		$current_blog_id = get_current_blog_id();
		$this->assertInternalType( 'integer', $current_blog_id );

		wp_cache_set( 'switch-test', $current_blog_id, 'switch-test' );
		$this->assertEquals( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );

		$blog_id = $this->factory->blog->create();

		$cap_key = wp_get_current_user()->cap_key;
		switch_to_blog( $blog_id );
		$this->assertNotEquals( $cap_key, wp_get_current_user()->cap_key );
		$this->assertEquals( array( $current_blog_id ), $_wp_switched_stack );
		$this->assertTrue( ms_is_switched() );
		$this->assertEquals( $blog_id, $wpdb->blogid );
		$this->assertFalse( wp_cache_get( 'switch-test', 'switch-test' ) );
		wp_cache_set( 'switch-test', $blog_id, 'switch-test' );
		$this->assertEquals( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );

		switch_to_blog( $blog_id );
		$this->assertEquals( array( $current_blog_id, $blog_id ), $_wp_switched_stack );
		$this->assertTrue( ms_is_switched() );
		$this->assertEquals( $blog_id, $wpdb->blogid );
		$this->assertEquals( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );

		restore_current_blog();
		$this->assertEquals( array( $current_blog_id ), $_wp_switched_stack );
		$this->assertTrue( ms_is_switched() );
		$this->assertEquals( $blog_id, $wpdb->blogid );
		$this->assertEquals( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );

		restore_current_blog();
		$this->assertEquals( $cap_key, wp_get_current_user()->cap_key );
		$this->assertEquals( $current_blog_id, get_current_blog_id() );
		$this->assertEquals( array(), $_wp_switched_stack );
		$this->assertFalse( ms_is_switched() );
		$this->assertEquals( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );

		$this->assertFalse( restore_current_blog() );
	}
 /**
  * Save meta boxes.
  *
  * @param int     $id
  * @param object  $post
  */
 public function save_meta_boxes($id, $post = null)
 {
     // Check if there was a multisite switch before.
     if (is_multisite() && ms_is_switched()) {
         return;
     }
     // Can't proceed without a id.
     if (empty($id)) {
         return;
     }
     // Check if our nonce is vailed.
     if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
         return;
     }
     $meta_type = $this->get_meta_type();
     $post = is_array($post) ? (object) $post : $post;
     if ($meta_type === 'post' && ($post_type = get_post_type_object($post->post_type))) {
         // Check so the id is a post id and not a autosave post.
         if ($this->valid_post_id($id)) {
             return;
         }
         // Check the `edit_posts` capability before we continue.
         if (!current_user_can($post_type->cap->edit_posts)) {
             return;
         }
         // Save post revision data.
         if ($parent_id = wp_is_post_revision($id)) {
             $slugs = papi_get_slugs($id, true);
             foreach ($slugs as $slug) {
                 papi_update_field($id, $slug, papi_get_field($parent_id, $slug));
             }
         }
     }
     if ($meta_type === 'term' && ($taxonomy = get_taxonomy(papi_get_taxonomy()))) {
         // Check the `edit_terms` capability before we continue.
         if ($taxonomy && !current_user_can($taxonomy->cap->edit_terms)) {
             return;
         }
     }
     $this->save_properties($id);
 }
示例#5
0
 /**
  * Save the WP SEO metadata for posts.
  *
  * @internal $_POST parameters are validated via sanitize_post_meta()
  *
  * @param int $post_id Post ID.
  *
  * @return  bool|void   Boolean false if invalid save post request
  */
 function save_postdata($post_id)
 {
     // Bail if this is a multisite installation and the site has been switched.
     if (is_multisite() && ms_is_switched()) {
         return false;
     }
     if ($post_id === null) {
         return false;
     }
     if (wp_is_post_revision($post_id)) {
         $post_id = wp_is_post_revision($post_id);
     }
     clean_post_cache($post_id);
     $post = get_post($post_id);
     if (!is_object($post)) {
         // Non-existent post.
         return false;
     }
     do_action('wpseo_save_compare_data', $post);
     $meta_boxes = apply_filters('wpseo_save_metaboxes', array());
     $meta_boxes = array_merge($meta_boxes, $this->get_meta_field_defs('general', $post->post_type), $this->get_meta_field_defs('advanced'));
     foreach ($meta_boxes as $key => $meta_box) {
         $data = null;
         if ('checkbox' === $meta_box['type']) {
             $data = isset($_POST[self::$form_prefix . $key]) ? 'on' : 'off';
         } else {
             if (isset($_POST[self::$form_prefix . $key])) {
                 $data = $_POST[self::$form_prefix . $key];
             }
         }
         if (isset($data)) {
             self::set_value($key, $data, $post_id);
         }
     }
     do_action('wpseo_saved_postdata');
 }
 public function init_settings()
 {
     if ($this->get_setting('setup_wizard_step') == 4 && $this->get_setting('setup_complete') && !ms_is_switched()) {
         global $sitepress_settings;
         $this->settings = get_option('icl_sitepress_settings');
         $sitepress_settings = $this->settings;
         return $sitepress_settings;
     }
     return null;
 }
示例#7
0
function icl_st_track_string($text, $context, $kind = ICL_STRING_TRANSLATION_STRING_TRACKING_TYPE_PAGE)
{
    if (is_multisite() && ms_is_switched()) {
        return;
    }
    require_once dirname(__FILE__) . '/gettext/wpml-string-scanner.class.php';
    static $string_scanner = null;
    if (!$string_scanner) {
        $string_scanner = new WPML_String_Scanner();
    }
    $string_scanner->track_string($text, $context, $kind);
}
示例#8
0
/**
 * Returns the Site Icon URL.
 *
 * @since 4.3.0
 *
 * @param int    $size    Optional. Size of the site icon. Default 512 (pixels).
 * @param string $url     Optional. Fallback url if no site icon is found. Default empty.
 * @param int    $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
 * @return string Site Icon URL.
 */
function get_site_icon_url($size = 512, $url = '', $blog_id = 0)
{
    if (is_multisite() && (int) $blog_id !== get_current_blog_id()) {
        switch_to_blog($blog_id);
    }
    $site_icon_id = get_option('site_icon');
    if ($site_icon_id) {
        if ($size >= 512) {
            $size_data = 'full';
        } else {
            $size_data = array($size, $size);
        }
        $url = wp_get_attachment_image_url($site_icon_id, $size_data);
    }
    if (is_multisite() && ms_is_switched()) {
        restore_current_blog();
    }
    /**
     * Filter the site icon URL.
     *
     * @site 4.4.0
     *
     * @param string $url     Site icon URL.
     * @param int    $size    Size of the site icon.
     * @param int    $blog_id ID of the blog to get the site icon for.
     */
    return apply_filters('get_site_icon_url', $url, $size, $blog_id);
}
 function importmedia($id, $prefix)
 {
     $delete = false;
     $attached_file = get_attached_file($id);
     $attached_file_option = get_post_meta($id, '_wp_attached_file', true);
     $basename = wp_basename($attached_file);
     $file_folder_path = trailingslashit(str_replace($basename, '', $attached_file));
     $siteurl = get_option('siteurl');
     $upload_path = trim(get_option('upload_path'));
     if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
         $dir = WP_CONTENT_DIR . '/uploads';
     } elseif (0 !== strpos($upload_path, ABSPATH)) {
         // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
         $dir = path_join(ABSPATH, $upload_path);
     } else {
         $dir = $upload_path;
     }
     if (!($url = get_option('upload_url_path'))) {
         if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
             $url = WP_CONTENT_URL . '/uploads';
         } else {
             $url = trailingslashit($siteurl) . $upload_path;
         }
     }
     // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
     // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
     if (defined('UPLOADS') && !(is_multisite() && rtmedia_get_site_option('ms_files_rewriting'))) {
         $dir = ABSPATH . UPLOADS;
         $url = trailingslashit($siteurl) . UPLOADS;
     }
     // If multisite (and if not the main site in a post-MU network)
     if (is_multisite() && !(is_main_site() && defined('MULTISITE'))) {
         if (!rtmedia_get_site_option('ms_files_rewriting')) {
             // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward:
             // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
             // prevents a four-digit ID from conflicting with a year-based directory for the main site.
             // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
             // directory, as they never had wp-content/uploads for the main site.)
             if (defined('MULTISITE')) {
                 $ms_dir = '/sites/' . get_current_blog_id();
             } else {
                 $ms_dir = '/' . get_current_blog_id();
             }
             $dir .= $ms_dir;
             $url .= $ms_dir;
         } elseif (defined('UPLOADS') && !ms_is_switched()) {
             // Handle the old-form ms-files.php rewriting if the network still has that enabled.
             // When ms-files rewriting is enabled, then we only listen to UPLOADS when:
             //   1) we are not on the main site in a post-MU network,
             //      as wp-content/uploads is used there, and
             //   2) we are not switched, as ms_upload_constants() hardcodes
             //      these constants to reflect the original blog ID.
             //
             // Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
             // (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
             // as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
             // rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
             if (defined('BLOGUPLOADDIR')) {
                 $dir = untrailingslashit(BLOGUPLOADDIR);
             } else {
                 $dir = ABSPATH . UPLOADS;
             }
             $url = trailingslashit($siteurl) . 'files';
         }
     }
     $basedir = trailingslashit($dir);
     $baseurl = trailingslashit($url);
     $new_file_folder_path = trailingslashit(str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $file_folder_path));
     $year_month = untrailingslashit(str_replace($basedir, '', $file_folder_path));
     $metadata = wp_get_attachment_metadata($id);
     $backup_metadata = get_post_meta($id, '_wp_attachment_backup_sizes', true);
     $instagram_thumbs = get_post_meta($id, '_instagram_thumbs', true);
     $instagram_full_images = get_post_meta($id, '_instagram_full_images', true);
     $instagram_metadata = get_post_meta($id, '_instagram_metadata', true);
     $encoding_job_id = get_post_meta($id, 'bp-media-encoding-job-id', true);
     $ffmpeg_thumbnail_ids = get_post_meta($id, 'bp_media_thumbnail_ids', true);
     $ffmpeg_thumbnail = get_post_meta($id, 'bp_media_thumbnail', true);
     $ffmpeg_remote_id = get_post_meta($id, 'bp_media_ffmpeg_remote_id', true);
     $kaltura_remote_id = get_post_meta($id, 'bp_media_kaltura_remote_id', true);
     if (wp_mkdir_p($basedir . "rtMedia/{$prefix}/" . $year_month)) {
         if (copy($attached_file, str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $attached_file))) {
             $delete = true;
             if (isset($metadata['sizes'])) {
                 foreach ($metadata['sizes'] as $size) {
                     if (!copy($file_folder_path . $size['file'], $new_file_folder_path . $size['file'])) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $file_folder_path . $size['file'];
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $size['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $size['file']);
                     }
                 }
             }
             if ($backup_metadata) {
                 foreach ($backup_metadata as $backup_images) {
                     if (!copy($file_folder_path . $backup_images['file'], $new_file_folder_path . $backup_images['file'])) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $file_folder_path . $backup_images['file'];
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $backup_images['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $backup_images['file']);
                     }
                 }
             }
             if ($instagram_thumbs) {
                 foreach ($instagram_thumbs as $key => $insta_thumb) {
                     try {
                         if (!copy(str_replace($baseurl, $basedir, $insta_thumb), str_replace($baseurl, $basedir . "rtMedia/{$prefix}/", $insta_thumb))) {
                             $delete = false;
                         } else {
                             $delete_sizes[] = str_replace($baseurl, $basedir, $insta_thumb);
                             $instagram_thumbs_new[$key] = str_replace($baseurl, $baseurl . "rtMedia/{$prefix}/", $insta_thumb);
                             $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_thumb, trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_thumb);
                         }
                     } catch (Exceptio $e) {
                         $delete = false;
                     }
                 }
             }
             if ($instagram_full_images) {
                 foreach ($instagram_full_images as $key => $insta_full_image) {
                     if (!copy($insta_full_image, str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $insta_full_image))) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $insta_full_image;
                         $instagram_full_images_new[$key] = str_replace($basedir, $basedir . "rtMedia/{$prefix}", $insta_full_image);
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_full_image, trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_full_image);
                     }
                 }
             }
             if ($instagram_metadata) {
                 $instagram_metadata_new = $instagram_metadata;
                 foreach ($instagram_metadata as $wp_size => $insta_metadata) {
                     if (isset($insta_metadata['file'])) {
                         if (!copy($basedir . $insta_metadata['file'], $basedir . "rtMedia/{$prefix}/" . $insta_metadata['file'])) {
                             $delete = false;
                         } else {
                             $delete_sizes[] = $basedir . $insta_metadata['file'];
                             $instagram_metadata_new[$wp_size]['file'] = "rtMedia/{$prefix}/" . $insta_metadata['file'];
                             if (isset($insta_metadata['sizes'])) {
                                 foreach ($insta_metadata['sizes'] as $key => $insta_size) {
                                     if (!copy($file_folder_path . $insta_size['file'], $new_file_folder_path . $insta_size['file'])) {
                                         $delete = false;
                                     } else {
                                         $delete_sizes[] = $file_folder_path . $insta_size['file'];
                                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_size['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_size['file']);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($delete) {
                 if (file_exists($attached_file)) {
                     unlink($attached_file);
                 }
                 if (isset($delete_sizes)) {
                     foreach ($delete_sizes as $delete_size) {
                         if (file_exists($delete_size)) {
                             unlink($delete_size);
                         }
                     }
                 }
                 update_post_meta($id, '_wp_attached_file', "rtMedia/{$prefix}/" . $attached_file_option);
                 if (isset($metadata['file'])) {
                     $metadata['file'] = "rtMedia/{$prefix}/" . $metadata['file'];
                     wp_update_attachment_metadata($id, $metadata);
                 }
                 if ($instagram_thumbs) {
                     update_rtmedia_meta($id, '_instagram_thumbs', $instagram_thumbs_new);
                 }
                 if ($instagram_full_images) {
                     update_rtmedia_meta($id, '_instagram_full_images', $instagram_full_images_new);
                 }
                 if ($instagram_metadata) {
                     update_rtmedia_meta($id, '_instagram_metadata', $instagram_metadata_new);
                 }
                 if ($encoding_job_id) {
                     update_rtmedia_meta($id, 'rtmedia-encoding-job-id', $encoding_job_id);
                 }
                 if ($ffmpeg_thumbnail_ids) {
                     update_rtmedia_meta($id, 'rtmedia-thumbnail-ids', $ffmpeg_thumbnail_ids);
                 }
                 if ($ffmpeg_thumbnail) {
                     $model = new RTMediaModel();
                     $model->update(array('cover_art' => $ffmpeg_thumbnail), array('id' => $id));
                 }
                 if ($ffmpeg_remote_id) {
                     update_rtmedia_meta($id, 'rtmedia-ffmpeg-remote-id', $ffmpeg_remote_id);
                 }
                 if ($kaltura_remote_id) {
                     update_rtmedia_meta($id, 'rtmedia-kaltura-remote-id', $kaltura_remote_id);
                 }
                 $attachment = array();
                 $attachment['ID'] = $id;
                 $old_guid = get_post_field('guid', $id);
                 $attachment['guid'] = str_replace($baseurl, $baseurl . "rtMedia/{$prefix}/", $old_guid);
                 /**
                  * For Activity
                  */
                 global $last_baseurl, $last_newurl;
                 $last_baseurl = $baseurl;
                 $last_newurl = $baseurl . "rtMedia/{$prefix}/";
                 $this->search_and_replace($old_guid, $attachment['guid']);
                 wp_update_post($attachment);
             }
         }
     }
 }
示例#10
0
 /**
  * Filter the stopwords from the slug
  *
  * @param string $slug       The current slug, if not empty there will be done nothing.
  * @param string $post_title The title which will be used in case of an empty slug.
  *
  * @return string
  */
 public function filter_stopwords_from_slug($slug, $post_title)
 {
     // Don't change an existing slug.
     if (isset($slug) && $slug !== '') {
         return $slug;
     }
     // When the post title is empty, just return the slug.
     if (empty($post_title)) {
         return $slug;
     }
     // Don't change the slug if this is a multisite installation and the site has been switched.
     if (is_multisite() && ms_is_switched()) {
         return $slug;
     }
     // Don't change slug if the post is a draft, this conflicts with polylang.
     // Doesn't work with filter_input() since need current value, not originally submitted one.
     if ('draft' === $_POST['post_status']) {
         return $slug;
     }
     // Lowercase the slug and strip slashes.
     $new_slug = sanitize_title(stripslashes($post_title));
     $stop_words = new WPSEO_Admin_Stop_Words();
     return $stop_words->remove_in($new_slug);
 }
示例#11
0
/**
 * Get an array containing the current upload directory's path and url.
 *
 * Checks the 'upload_path' option, which should be from the web root folder,
 * and if it isn't empty it will be used. If it is empty, then the path will be
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
 *
 * The upload URL path is set either by the 'upload_url_path' option or by using
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
 *
 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
 * the administration settings panel), then the time will be used. The format
 * will be year first and then month.
 *
 * If the path couldn't be created, then an error will be returned with the key
 * 'error' containing the error message. The error suggests that the parent
 * directory is not writable by the server.
 *
 * On success, the returned array will have many indices:
 * 'path' - base directory and sub directory or full path to upload directory.
 * 'url' - base url and sub directory or absolute URL to upload directory.
 * 'subdir' - sub directory if uploads use year/month folders option is on.
 * 'basedir' - path without subdir.
 * 'baseurl' - URL path without subdir.
 * 'error' - set to false.
 *
 * @since 2.0.0
 * @uses apply_filters() Calls 'upload_dir' on returned array.
 *
 * @param string $time Optional. Time formatted in 'yyyy/mm'.
 * @return array See above for description.
 */
function wp_upload_dir($time = null)
{
    $siteurl = get_option('siteurl');
    $upload_path = trim(get_option('upload_path'));
    if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } elseif (0 !== strpos($upload_path, ABSPATH)) {
        // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
        $dir = path_join(ABSPATH, $upload_path);
    } else {
        $dir = $upload_path;
    }
    if (!($url = get_option('upload_url_path'))) {
        if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
            $url = WP_CONTENT_URL . '/uploads';
        } else {
            $url = trailingslashit($siteurl) . $upload_path;
        }
    }
    if (defined('UPLOADS')) {
        $dir = ABSPATH . UPLOADS;
        $url = trailingslashit($siteurl) . UPLOADS;
    }
    // If multisite (if not the main site in a post-MU network)
    $blog_id = get_current_blog_id();
    if (is_multisite() && !(is_main_site($blog_id) && defined('MULTISITE'))) {
        if (!get_site_option('ms_files_rewriting')) {
            // Append sites/%d if we're not on the main site (for post-MU networks). The extra directory
            // prevents a four-digit ID from conflicting with a year-based directory for the main site.
            // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
            // directory, as they never had wp-content/uploads for the main site.
            $ms_dir = defined('MULTISITE') ? '/sites/' : '/';
            $dir .= $ms_dir . $blog_id;
            $url .= $ms_dir . $blog_id;
        } elseif (!ms_is_switched()) {
            // Handle the old-form ms-files.php rewriting if the network still has that enabled.
            if (defined('BLOGUPLOADDIR')) {
                $dir = untrailingslashit(BLOGUPLOADDIR);
            }
            $url = str_replace(UPLOADS, 'files', $url);
        }
    }
    $basedir = $dir;
    $baseurl = $url;
    $subdir = '';
    if (get_option('uploads_use_yearmonth_folders')) {
        // Generate the yearly and monthly dirs
        if (!$time) {
            $time = current_time('mysql');
        }
        $y = substr($time, 0, 4);
        $m = substr($time, 5, 2);
        $subdir = "/{$y}/{$m}";
    }
    $dir .= $subdir;
    $url .= $subdir;
    $uploads = apply_filters('upload_dir', array('path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $basedir, 'baseurl' => $baseurl, 'error' => false));
    // Make sure we have an uploads dir
    if (!wp_mkdir_p($uploads['path'])) {
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $uploads['path']);
        $uploads['error'] = $message;
    }
    return $uploads;
}
function cud_wp_upload_dir($time = null)
{
    $upload_path = trim(get_option('upload_path'));
    $basedir = '';
    if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
        $basedir = WP_CONTENT_DIR . '/uploads';
    } elseif (0 !== strpos($upload_path, ABSPATH)) {
        // $basedir is absolute, $upload_path is (maybe) relative to ABSPATH
        $basedir = path_join(ABSPATH, $upload_path);
    } else {
        $basedir = $upload_path;
    }
    // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
    // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
    if (defined('UPLOADS') && !(is_multisite() && get_site_option('ms_files_rewriting'))) {
        $basedir = ABSPATH . UPLOADS;
    }
    // If multisite (and if not the main site in a post-MU network)
    if (is_multisite() && !(is_main_site() && defined('MULTISITE'))) {
        if (!get_site_option('ms_files_rewriting')) {
            // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward:
            // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
            // prevents a four-digit ID from conflicting with a year-based directory for the main site.
            // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
            // directory, as they never had wp-content/uploads for the main site.)
            if (defined('MULTISITE')) {
                $ms_dir = '/sites/' . get_current_blog_id();
            } else {
                $ms_dir = '/' . get_current_blog_id();
            }
            $basedir .= $ms_dir;
        } elseif (defined('UPLOADS') && !ms_is_switched()) {
            // Handle the old-form ms-files.php rewriting if the network still has that enabled.
            // When ms-files rewriting is enabled, then we only listen to UPLOADS when:
            //   1) we are not on the main site in a post-MU network,
            //      as wp-content/uploads is used there, and
            //   2) we are not switched, as ms_upload_constants() hardcodes
            //      these constants to reflect the original blog ID.
            //
            // Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
            // (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
            // as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
            // rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
            if (defined('BLOGUPLOADDIR')) {
                $basedir = untrailingslashit(BLOGUPLOADDIR);
            } else {
                $basedir = ABSPATH . UPLOADS;
            }
        }
    }
    return $basedir;
}
示例#13
0
function icl_st_track_string($text, $domain, $kind = ICL_STRING_TRANSLATION_STRING_TRACKING_TYPE_PAGE)
{
    if (is_multisite() && ms_is_switched()) {
        return;
    }
    require_once dirname(__FILE__) . '/gettext/wpml-string-scanner.class.php';
    static $string_scanner = null;
    if (!$string_scanner) {
        try {
            $wp_filesystem = wp_filesystem_init();
            $string_scanner = new WPML_String_Scanner($wp_filesystem);
        } catch (Exception $e) {
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
    }
    if ($string_scanner) {
        $string_scanner->track_string($text, $domain, $kind);
    }
}
 /**
  * After a test method runs, reset any state in WordPress the test method might have changed.
  */
 function tearDown()
 {
     global $wpdb, $wp_query, $wp;
     $wpdb->query('ROLLBACK');
     if (is_multisite()) {
         while (ms_is_switched()) {
             restore_current_blog();
         }
     }
     $wp_query = new WP_Query();
     $wp = new WP();
     // Reset globals related to the post loop and `setup_postdata()`.
     $post_globals = array('post', 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages');
     foreach ($post_globals as $global) {
         $GLOBALS[$global] = null;
     }
     remove_theme_support('html5');
     remove_filter('query', array($this, '_create_temporary_tables'));
     remove_filter('query', array($this, '_drop_temporary_tables'));
     remove_filter('wp_die_handler', array($this, 'get_wp_die_handler'));
     $this->_restore_hooks();
     wp_set_current_user(0);
 }
示例#15
0
 public function save_post($post_id)
 {
     // We must be on the source blog.
     if (ms_is_switched()) {
         $this->debug('Blog is switched. Not broadcasting.');
         return;
     }
     // Loop check.
     if ($this->is_broadcasting()) {
         $this->debug('Already broadcasting.');
         return;
     }
     // We must handle this post type.
     $post = get_post($post_id);
     $action = new actions\get_post_types();
     $action->execute();
     if (!in_array($post->post_type, $action->post_types)) {
         return $this->debug('We do not care about the %s post type.', $post->post_type);
     }
     // No post?
     if (count($_POST) < 1) {
         return $this->debug('No _POST available. Not broadcasting.');
     }
     // Does this post_id match up with the one in the post?
     $_post_id = $_POST['ID'];
     if (isset($_post_id)) {
         if ($_post_id != $post_id) {
             return $this->debug('Post ID %s does not match up with ID in POST %s.', $post_id, $_post_id);
         }
     }
     // Is this post a child?
     $broadcast_data = $this->get_post_broadcast_data(get_current_blog_id(), $post_id);
     if ($broadcast_data->get_linked_parent() !== false) {
         return $this->debug('Post is a child. Not broadcasting.');
     }
     // No permission.
     if (!static::user_has_roles($this->get_site_option('role_broadcast'))) {
         return $this->debug('User does not have permission to use Broadcast. Not broadcasting.');
     }
     // Save the user's last settings.
     if (isset($_POST['broadcast'])) {
         $this->save_last_used_settings($this->user_id(), $_POST['broadcast']);
     }
     $this->debug('We are currently on blog %s (%s).', get_bloginfo('blogname'), get_current_blog_id());
     $broadcasting_data = new broadcasting_data(['parent_post_id' => $post_id]);
     $this->debug('Preparing the broadcasting data.');
     // This is to fetch the selected blogs from the meta box.
     $action = new actions\prepare_broadcasting_data();
     $action->broadcasting_data = $broadcasting_data;
     $action->execute();
     $this->debug('Broadcasting data prepared.');
     if ($broadcasting_data->has_blogs()) {
         $this->filters('threewp_broadcast_broadcast_post', $broadcasting_data);
     } else {
         $this->debug('No blogs are selected. Not broadcasting.');
     }
 }
 /**
  * Get the prefix path for the files. Ignores WP media library
  * year month subdirectory setting and just uses S3 setting
  *
  * @param string $time
  *
  * @return string
  */
 function get_dynamic_prefix($time = null)
 {
     $prefix = '';
     $subdir = '';
     // If multisite (and if not the main site in a post-MU network)
     if (is_multisite() && !(is_main_network() && is_main_site() && defined('MULTISITE'))) {
         if (!get_site_option('ms_files_rewriting')) {
             /*
              * If ms-files rewriting is disabled (networks created post-3.5), it is fairly
              * straightforward: Append sites/%d if we're not on the main site (for post-MU
              * networks). (The extra directory prevents a four-digit ID from conflicting with
              * a year-based directory for the main site. But if a MU-era network has disabled
              * ms-files rewriting manually, they don't need the extra directory, as they never
              * had wp-content/uploads for the main site.)
              */
             if (defined('MULTISITE')) {
                 $prefix = '/sites/' . get_current_blog_id();
             } else {
                 $prefix = '/' . get_current_blog_id();
             }
         } elseif (defined('UPLOADS') && !ms_is_switched()) {
             /*
              * Handle the old-form ms-files.php rewriting if the network still has that enabled.
              * When ms-files rewriting is enabled, then we only listen to UPLOADS when:
              * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
              *    there, and
              * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
              *    the original blog ID.
              *
              * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
              * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
              * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
              * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
              */
             if (defined('BLOGUPLOADDIR')) {
                 $prefix = untrailingslashit(BLOGUPLOADDIR);
             } else {
                 $prefix = ABSPATH . UPLOADS;
             }
         }
     }
     if ($this->get_setting('use-yearmonth-folders')) {
         $subdir = $this->get_year_month_directory_name($time);
         $prefix .= $subdir;
     }
     // support legacy MS installs (<3.5 since upgraded) for subsites
     if (is_multisite() && !(is_main_network() && is_main_site()) && false === strpos($prefix, 'sites/')) {
         $details = get_blog_details(get_current_blog_id());
         $legacy_ms_prefix = 'sites/' . $details->blog_id . '/';
         $legacy_ms_prefix = apply_filters('as3cf_legacy_ms_subsite_prefix', $legacy_ms_prefix, $details);
         $prefix = '/' . trailingslashit(ltrim($legacy_ms_prefix, '/')) . ltrim($subdir, '/');
     }
     return $prefix;
 }
示例#17
0
 /**
  * Wrapper for \ms_is_switched
  *
  * @return bool
  */
 public function ms_is_switched()
 {
     return ms_is_switched();
 }
示例#18
0
/**
 * Returns a custom logo, linked to home.
 *
 * @since 4.5.0
 *
 * @param int $blog_id Optional. ID of the blog in question. Default current blog.
 * @return string Custom logo markup.
 */
function get_custom_logo($blog_id = 0)
{
    $html = '';
    if (is_multisite() && (int) $blog_id !== get_current_blog_id()) {
        switch_to_blog($blog_id);
    }
    $custom_logo_id = get_theme_mod('custom_logo');
    if (is_multisite() && ms_is_switched()) {
        restore_current_blog();
    }
    $size = get_theme_support('custom-logo');
    $size = $size[0]['size'];
    // We have a logo. Logo is go.
    if ($custom_logo_id) {
        $html = sprintf('<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>', esc_url(home_url('/')), wp_get_attachment_image($custom_logo_id, $size, false, array('class' => "custom-logo attachment-{$size}", 'data-size' => $size, 'itemprop' => 'logo')));
    } elseif (is_customize_preview()) {
        $html = sprintf('<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" data-size="%2$s" /></a>', esc_url(home_url('/')), esc_attr($size));
    }
    /**
     * Filter the custom logo output.
     *
     * @since 4.5.0
     *
     * @param string $html Custom logo HTML output.
     * @param string $size Size specified in add_theme_support declaration, or 'thumbnail' default.
     */
    return apply_filters('get_custom_logo', $html, $size);
}
示例#19
0
/**
 * Returns a custom logo, linked to home.
 *
 * @since 4.5.0
 *
 * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
 * @return string Custom logo markup.
 */
function get_custom_logo($blog_id = 0)
{
    $html = '';
    if (is_multisite() && (int) $blog_id !== get_current_blog_id()) {
        switch_to_blog($blog_id);
    }
    $custom_logo_id = get_theme_mod('custom_logo');
    // We have a logo. Logo is go.
    if ($custom_logo_id) {
        $html = sprintf('<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>', esc_url(home_url('/')), wp_get_attachment_image($custom_logo_id, 'full', false, array('class' => 'custom-logo', 'itemprop' => 'logo')));
    } elseif (is_customize_preview()) {
        $html = sprintf('<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>', esc_url(home_url('/')));
    }
    if (is_multisite() && ms_is_switched()) {
        restore_current_blog();
    }
    /**
     * Filters the custom logo output.
     *
     * @since 4.5.0
     * @since 4.6.0 Added the `$blog_id` parameter.
     *
     * @param string $html    Custom logo HTML output.
     * @param int    $blog_id ID of the blog to get the custom logo for.
     */
    return apply_filters('get_custom_logo', $html, $blog_id);
}
 /**
  * Check if the current request should be processed by save().
  *
  * @param WP_Post $post
  *
  * @return bool
  */
 private function is_valid_save_request(WP_Post $post)
 {
     static $called = 0;
     if (ms_is_switched()) {
         return false;
     }
     if (empty($this->post_request_data)) {
         return false;
     }
     if (!empty($this->post_request_data['original_post_status']) && 'auto-draft' === $this->post_request_data['original_post_status'] && 1 < $called) {
         return false;
     }
     if (empty($this->post_request_data[$this->name_base])) {
         return false;
     }
     if (!is_array($this->post_request_data[$this->name_base])) {
         return false;
     }
     // We only need this when the post is published or drafted.
     if (!$this->is_connectable_status($post)) {
         return false;
     }
     // For auto-drafts, 'save_post' is called twice, resulting in doubled drafts for translations.
     $called++;
     return true;
 }
示例#21
0
 /**
  * Determine if the request to save data should be allowed to proceed.
  *
  * @since  0.3.0
  * @access protected
  * @param  int $post_id Post ID.
  * @return bool Whether or not this is a valid request to save our data.
  */
 protected function validate_request($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return false;
     }
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return false;
     }
     if (defined('DOING_CRON') && DOING_CRON) {
         return false;
     }
     if (!current_user_can('edit_post', $post_id)) {
         return false;
     }
     if (!isset($this->user_data[$this->nonce_name])) {
         return false;
     }
     if (!wp_verify_nonce($this->user_data[$this->nonce_name], $this->nonce_action)) {
         return false;
     }
     // @link http://make.marketpress.com/multilingualpress/2014/10/how-to-disable-broken-save_post-callbacks/
     if (is_multisite() && ms_is_switched()) {
         return false;
     }
     return true;
 }
示例#22
0
/**
 * Get an array containing the current upload directory's path and url.
 *
 * Checks the 'upload_path' option, which should be from the web root folder,
 * and if it isn't empty it will be used. If it is empty, then the path will be
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
 *
 * The upload URL path is set either by the 'upload_url_path' option or by using
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
 *
 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
 * the administration settings panel), then the time will be used. The format
 * will be year first and then month.
 *
 * If the path couldn't be created, then an error will be returned with the key
 * 'error' containing the error message. The error suggests that the parent
 * directory is not writable by the server.
 *
 * On success, the returned array will have many indices:
 * 'path' - base directory and sub directory or full path to upload directory.
 * 'url' - base url and sub directory or absolute URL to upload directory.
 * 'subdir' - sub directory if uploads use year/month folders option is on.
 * 'basedir' - path without subdir.
 * 'baseurl' - URL path without subdir.
 * 'error' - set to false.
 *
 * @since 2.0.0
 * @uses apply_filters() Calls 'upload_dir' on returned array.
 *
 * @param string $time Optional. Time formatted in 'yyyy/mm'.
 * @return array See above for description.
 */
function wp_upload_dir($time = null)
{
    $siteurl = get_option('siteurl');
    $upload_path = trim(get_option('upload_path'));
    if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } elseif (0 !== strpos($upload_path, ABSPATH)) {
        // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
        $dir = path_join(ABSPATH, $upload_path);
    } else {
        $dir = $upload_path;
    }
    if (!($url = get_option('upload_url_path'))) {
        if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
            $url = WP_CONTENT_URL . '/uploads';
        } else {
            $url = trailingslashit($siteurl) . $upload_path;
        }
    }
    // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
    // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
    if (defined('UPLOADS') && !(is_multisite() && get_site_option('ms_files_rewriting'))) {
        $dir = ABSPATH . UPLOADS;
        $url = trailingslashit($siteurl) . UPLOADS;
    }
    // If multisite (and if not the main site in a post-MU network)
    if (is_multisite() && !(is_main_site() && defined('MULTISITE'))) {
        if (!get_site_option('ms_files_rewriting')) {
            // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward:
            // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
            // prevents a four-digit ID from conflicting with a year-based directory for the main site.
            // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
            // directory, as they never had wp-content/uploads for the main site.)
            if (defined('MULTISITE')) {
                $ms_dir = '/sites/' . get_current_blog_id();
            } else {
                $ms_dir = '/' . get_current_blog_id();
            }
            $dir .= $ms_dir;
            $url .= $ms_dir;
        } elseif (defined('UPLOADS') && !ms_is_switched()) {
            // Handle the old-form ms-files.php rewriting if the network still has that enabled.
            // When ms-files rewriting is enabled, then we only listen to UPLOADS when:
            //   1) we are not on the main site in a post-MU network,
            //      as wp-content/uploads is used there, and
            //   2) we are not switched, as ms_upload_constants() hardcodes
            //      these constants to reflect the original blog ID.
            if (defined('BLOGUPLOADDIR')) {
                $dir = untrailingslashit(BLOGUPLOADDIR);
            }
            $url = str_replace(UPLOADS, 'files', $url);
        }
    }
    $basedir = $dir;
    $baseurl = $url;
    $subdir = '';
    if (get_option('uploads_use_yearmonth_folders')) {
        // Generate the yearly and monthly dirs
        if (!$time) {
            $time = current_time('mysql');
        }
        $y = substr($time, 0, 4);
        $m = substr($time, 5, 2);
        $subdir = "/{$y}/{$m}";
    }
    $dir .= $subdir;
    $url .= $subdir;
    $uploads = apply_filters('upload_dir', array('path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $basedir, 'baseurl' => $baseurl, 'error' => false));
    // Make sure we have an uploads dir
    if (!wp_mkdir_p($uploads['path'])) {
        if (0 === strpos($uploads['basedir'], ABSPATH)) {
            $error_path = str_replace(ABSPATH, '', $uploads['basedir']) . $uploads['subdir'];
        } else {
            $error_path = basename($uploads['basedir']) . $uploads['subdir'];
        }
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
        $uploads['error'] = $message;
    }
    return $uploads;
}
示例#23
0
/**
 * If siteurl, home or page_on_front changed, flush rewrite rules.
 *
 * @since 2.1.0
 *
 * @param string $old_value
 * @param string $value
 */
function update_home_siteurl($old_value, $value)
{
    if (defined("WP_INSTALLING")) {
        return;
    }
    if (is_multisite() && ms_is_switched()) {
        delete_option('rewrite_rules');
    } else {
        flush_rewrite_rules();
    }
}
function get_site_icon_url($size = 512, $url = '', $blog_id = 0)
{
    if (is_multisite() && (int) $blog_id !== get_current_blog_id()) {
        switch_to_blog($blog_id);
    }
    $site_icon_id = get_option('site_icon');
    if ($site_icon_id) {
        if ($size >= 512) {
            $size_data = 'full';
        } else {
            $size_data = array($size, $size);
        }
        $url = wp_get_attachment_image_url($site_icon_id, $size_data);
    }
    if (is_multisite() && ms_is_switched()) {
        restore_current_blog();
    }
    return apply_filters('get_site_icon_url', $url, $size, $blog_id);
}
/**
 * On deactivation, flush the rewrite rules so XML sitemaps stop working.
 */
function _wpseo_deactivate()
{
    require_once WPSEO_PATH . 'inc/wpseo-functions.php';
    if (is_multisite() && ms_is_switched()) {
        delete_option('rewrite_rules');
    } else {
        add_action('shutdown', 'flush_rewrite_rules');
    }
    wpseo_remove_capabilities();
    // Clear cache so the changes are obvious.
    WPSEO_Utils::clear_cache();
    do_action('wpseo_deactivate');
}
 /**
  * Only ever save a single term
  *
  * @param  int $post_id
  * @return int
  * @since 1.1.0
  */
 function save_single_term($post_id)
 {
     // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // prevent weirdness with multisite
     if (function_exists('ms_is_switched') && ms_is_switched()) {
         return $post_id;
     }
     // make sure we're on a supported post type
     if (is_array($this->tax_obj->object_type) && isset($_REQUEST['post_type']) && !in_array($_REQUEST['post_type'], $this->tax_obj->object_type)) {
         return $post_id;
     }
     // verify nonce
     if (isset($_POST["_radio_nonce-{$this->taxonomy}"]) && !wp_verify_nonce($_REQUEST["_radio_nonce-{$this->taxonomy}"], "radio_nonce-{$this->taxonomy}")) {
         return $post_id;
     }
     // OK, we must be authenticated by now: we need to find and save the data
     if (isset($_REQUEST["radio_tax_input"]["{$this->taxonomy}"])) {
         $terms = (array) $_REQUEST["radio_tax_input"]["{$this->taxonomy}"];
         // if category and not saving any terms, set to default
         if ('category' == $this->taxonomy && empty($terms)) {
             $single_term = intval(get_option('default_category'));
         }
         // make sure we're only saving 1 term
         $single_term = intval(array_shift($terms));
         // set the single terms
         if (current_user_can($this->tax_obj->cap->assign_terms)) {
             wp_set_object_terms($post_id, $single_term, $this->taxonomy);
         }
     }
     return $post_id;
 }
示例#27
0
/**
 * Flushes rewrite rules if siteurl, home or page_on_front changed.
 *
 * @since 2.1.0
 *
 * @param string $old_value
 * @param string $value
 */
function update_home_siteurl($old_value, $value)
{
    if (wp_installing()) {
        return;
    }
    if (is_multisite() && ms_is_switched()) {
        delete_option('rewrite_rules');
    } else {
        flush_rewrite_rules();
    }
}
示例#28
0
 /**
  * Save the WP SEO metadata for posts.
  *
  * @internal $_POST parameters are validated via sanitize_post_meta()
  *
  * @param int $post_id Post ID.
  *
  * @return  bool|void   Boolean false if invalid save post request
  */
 function save_postdata($post_id)
 {
     // Bail if this is a multisite installation and the site has been switched.
     if (is_multisite() && ms_is_switched()) {
         return false;
     }
     if ($post_id === null) {
         return false;
     }
     if (wp_is_post_revision($post_id)) {
         $post_id = wp_is_post_revision($post_id);
     }
     /**
      * Determine we're not accidentally updating a different post.
      * We can't use filter_input here as the ID isn't available at this point, other than in the $_POST data.
      */
     if (!isset($_POST['ID']) || $post_id !== (int) $_POST['ID']) {
         return false;
     }
     clean_post_cache($post_id);
     $post = get_post($post_id);
     if (!is_object($post)) {
         // Non-existent post.
         return false;
     }
     do_action('wpseo_save_compare_data', $post);
     $meta_boxes = apply_filters('wpseo_save_metaboxes', array());
     $meta_boxes = array_merge($meta_boxes, $this->get_meta_field_defs('general', $post->post_type), $this->get_meta_field_defs('advanced'));
     foreach ($meta_boxes as $key => $meta_box) {
         // If analysis is disabled remove that analysis score value from the DB.
         if ($this->is_meta_value_disabled($key)) {
             self::delete($key, $post_id);
             continue;
         }
         $data = null;
         if ('checkbox' === $meta_box['type']) {
             $data = isset($_POST[self::$form_prefix . $key]) ? 'on' : 'off';
         } else {
             if (isset($_POST[self::$form_prefix . $key])) {
                 $data = $_POST[self::$form_prefix . $key];
             }
         }
         if (isset($data)) {
             self::set_value($key, $data, $post_id);
         }
     }
     do_action('wpseo_saved_postdata');
 }
示例#29
0
/**
 * Get an array containing the current upload directory's path and url.
 *
 * Checks the 'upload_path' option, which should be from the web root folder,
 * and if it isn't empty it will be used. If it is empty, then the path will be
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
 *
 * The upload URL path is set either by the 'upload_url_path' option or by using
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
 *
 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
 * the administration settings panel), then the time will be used. The format
 * will be year first and then month.
 *
 * If the path couldn't be created, then an error will be returned with the key
 * 'error' containing the error message. The error suggests that the parent
 * directory is not writable by the server.
 *
 * On success, the returned array will have many indices:
 * 'path' - base directory and sub directory or full path to upload directory.
 * 'url' - base url and sub directory or absolute URL to upload directory.
 * 'subdir' - sub directory if uploads use year/month folders option is on.
 * 'basedir' - path without subdir.
 * 'baseurl' - URL path without subdir.
 * 'error' - set to false.
 *
 * @since 2.0.0
 *
 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
 * @return array See above for description.
 */
function wp_upload_dir($time = null)
{
    $siteurl = get_option('siteurl');
    $upload_path = trim(get_option('upload_path'));
    if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } elseif (0 !== strpos($upload_path, ABSPATH)) {
        // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
        $dir = path_join(ABSPATH, $upload_path);
    } else {
        $dir = $upload_path;
    }
    if (!($url = get_option('upload_url_path'))) {
        if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
            $url = WP_CONTENT_URL . '/uploads';
        } else {
            $url = trailingslashit($siteurl) . $upload_path;
        }
    }
    /*
     * Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
     * We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
     */
    if (defined('UPLOADS') && !(is_multisite() && get_site_option('ms_files_rewriting'))) {
        $dir = ABSPATH . UPLOADS;
        $url = trailingslashit($siteurl) . UPLOADS;
    }
    // If multisite (and if not the main site in a post-MU network)
    if (is_multisite() && !(is_main_network() && is_main_site() && defined('MULTISITE'))) {
        if (!get_site_option('ms_files_rewriting')) {
            /*
             * If ms-files rewriting is disabled (networks created post-3.5), it is fairly
             * straightforward: Append sites/%d if we're not on the main site (for post-MU
             * networks). (The extra directory prevents a four-digit ID from conflicting with
             * a year-based directory for the main site. But if a MU-era network has disabled
             * ms-files rewriting manually, they don't need the extra directory, as they never
             * had wp-content/uploads for the main site.)
             */
            if (defined('MULTISITE')) {
                $ms_dir = '/sites/' . get_current_blog_id();
            } else {
                $ms_dir = '/' . get_current_blog_id();
            }
            $dir .= $ms_dir;
            $url .= $ms_dir;
        } elseif (defined('UPLOADS') && !ms_is_switched()) {
            /*
             * Handle the old-form ms-files.php rewriting if the network still has that enabled.
             * When ms-files rewriting is enabled, then we only listen to UPLOADS when:
             * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
             *    there, and
             * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
             *    the original blog ID.
             *
             * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
             * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
             * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
             * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
             */
            if (defined('BLOGUPLOADDIR')) {
                $dir = untrailingslashit(BLOGUPLOADDIR);
            } else {
                $dir = ABSPATH . UPLOADS;
            }
            $url = trailingslashit($siteurl) . 'files';
        }
    }
    $basedir = $dir;
    $baseurl = $url;
    $subdir = '';
    if (get_option('uploads_use_yearmonth_folders')) {
        // Generate the yearly and monthly dirs
        if (!$time) {
            $time = current_time('mysql');
        }
        $y = substr($time, 0, 4);
        $m = substr($time, 5, 2);
        $subdir = "/{$y}/{$m}";
    }
    $dir .= $subdir;
    $url .= $subdir;
    /**
     * Filter the uploads directory data.
     *
     * @since 2.0.0
     *
     * @param array $uploads Array of upload directory data with keys of 'path',
     *                       'url', 'subdir, 'basedir', and 'error'.
     */
    $uploads = apply_filters('upload_dir', array('path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $basedir, 'baseurl' => $baseurl, 'error' => false));
    // Make sure we have an uploads directory.
    if (!wp_mkdir_p($uploads['path'])) {
        if (0 === strpos($uploads['basedir'], ABSPATH)) {
            $error_path = str_replace(ABSPATH, '', $uploads['basedir']) . $uploads['subdir'];
        } else {
            $error_path = basename($uploads['basedir']) . $uploads['subdir'];
        }
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
        $uploads['error'] = $message;
    }
    return $uploads;
}
function sp_get_upload_info()
{
    $siteurl = get_option('siteurl');
    $upload_path = trim(get_option('upload_path'));
    if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } elseif (0 !== strpos($upload_path, ABSPATH)) {
        # $dir is absolute, $upload_path is (maybe) relative to ABSPATH
        $dir = path_join(ABSPATH, $upload_path);
    } else {
        $dir = $upload_path;
    }
    if (!($url = get_option('upload_url_path'))) {
        if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
            $url = WP_CONTENT_URL . '/uploads';
        } else {
            $url = trailingslashit($siteurl) . $upload_path;
        }
    }
    /*
     * Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
     * We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
     */
    if (defined('UPLOADS') && !(is_multisite() && get_site_option('ms_files_rewriting'))) {
        $dir = ABSPATH . UPLOADS;
        $url = trailingslashit($siteurl) . UPLOADS;
    }
    # If multisite (and if not the main site in a post-MU network)
    if (is_multisite() && !(is_main_network() && is_main_site() && defined('MULTISITE'))) {
        if (!get_site_option('ms_files_rewriting')) {
            /*
             * If ms-files rewriting is disabled (networks created post-3.5), it is fairly
             * straightforward: Append sites/%d if we're not on the main site (for post-MU
             * networks). (The extra directory prevents a four-digit ID from conflicting with
             * a year-based directory for the main site. But if a MU-era network has disabled
             * ms-files rewriting manually, they don't need the extra directory, as they never
             * had wp-content/uploads for the main site.)
             */
            if (defined('MULTISITE')) {
                $ms_dir = '/sites/' . get_current_blog_id();
            } else {
                $ms_dir = '/' . get_current_blog_id();
            }
            $dir .= $ms_dir;
            $url .= $ms_dir;
        } elseif (defined('UPLOADS') && !ms_is_switched()) {
            /*
             * Handle the old-form ms-files.php rewriting if the network still has that enabled.
             * When ms-files rewriting is enabled, then we only listen to UPLOADS when:
             * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
             *    there, and
             * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
             *    the original blog ID.
             *
             * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
             * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
             * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
             * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
             */
            if (defined('BLOGUPLOADDIR')) {
                $dir = untrailingslashit(BLOGUPLOADDIR);
            } else {
                $dir = ABSPATH . UPLOADS;
            }
            $url = trailingslashit($siteurl) . 'files';
        }
    }
    $uploads = array('basedir' => $dir, 'baseurl' => $url);
    return $uploads;
}