/** * Factory method * @param int $id * @return MslsOptions */ public static function create($id = 0) { if (is_admin()) { $id = (int) $id; if (MslsContentTypes::create()->is_taxonomy()) { return MslsOptionsTax::create($id); } return new MslsOptionsPost($id); } if (self::is_main_page()) { return new MslsOptions(); } elseif (self::is_tax_page()) { return MslsOptionsTax::create(); } elseif (self::is_query_page()) { return MslsOptionsQuery::create(); } global $wp_query; return new MslsOptionsPost($wp_query->get_queried_object_id()); }
/** * Factory method * * @param int $id * * @return MslsOptions */ public static function create($id = 0) { if (is_admin()) { $id = (int) $id; if (MslsContentTypes::create()->is_taxonomy()) { return MslsOptionsTax::create($id); } return new MslsOptionsPost($id); } if (self::is_main_page()) { $options = new MslsOptions(); } elseif (self::is_tax_page()) { $options = MslsOptionsTax::create(); } elseif (self::is_query_page()) { $options = MslsOptionsQuery::create(); } else { $options = new MslsOptionsPost(get_queried_object_id()); } add_filter('check_url', array($options, 'check_for_blog_slug'), 10, 2); return $options; }
/** * Print the input fields * Returns true if the blogcollection is not empty * @param StdClass $tag * @param string $title_format * @param string $item_format * @return boolean */ public function the_input($tag, $title_format, $item_format) { $blogs = MslsBlogCollection::instance()->get(); if ($blogs) { $term_id = is_object($tag) ? $tag->term_id : 0; $mydata = MslsOptionsTax::create($term_id); $type = MslsContentTypes::create()->get_request(); printf($title_format, __('Multisite Language Switcher', 'multisite-language-switcher')); foreach ($blogs as $blog) { $this->print_option($blog, $type, $mydata, $item_format); } return true; } return false; }
/** * Print the input fields * Returns true if the blogcollection is not empty * @param StdClass $tag * @param string $title_format * @param string $item_format * @return boolean */ public function the_input($tag, $title_format, $item_format) { $term_id = is_object($tag) ? $tag->term_id : 0; $blogs = MslsBlogCollection::instance()->get(); if ($blogs) { $my_data = MslsOptionsTax::create($term_id); $type = MslsContentTypes::create()->get_request(); printf($title_format, __('Multisite Language Switcher', 'msls'), $type); foreach ($blogs as $blog) { switch_to_blog($blog->userblog_id); $language = $blog->get_language(); $flag_url = MslsOptions::instance()->get_flag_url($language); $icon = MslsAdminIcon::create()->set_language($language)->set_src($flag_url); $value = $title = ''; if ($my_data->has_value($language)) { $term = get_term($my_data->{$language}, $type); if (is_object($term)) { $icon->set_href($my_data->{$language}); $value = $my_data->{$language}; $title = $term->name; } } printf($item_format, $blog->userblog_id, $icon, $language, $value, $title); restore_current_blog(); } return true; } return false; }
/** * Verify the static create-method */ function test_create_method() { $obj = MslsOptionsTax::create(); $this->assertInstanceOf('MslsOptionsTax', $obj); return $obj; }