/** * Test get_return_url()/set_return_url() methods. * * @see WP_Customize_Manager::get_return_url() * @see WP_Customize_Manager::set_return_url() */ function test_return_url() { wp_set_current_user( self::factory()->user->create( array( 'role' => 'author' ) ) ); $this->assertEquals( home_url( '/' ), $this->manager->get_return_url() ); wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); $this->assertTrue( current_user_can( 'edit_theme_options' ) ); $this->assertEquals( home_url( '/' ), $this->manager->get_return_url() ); $preview_url = home_url( '/foo/' ); $this->manager->set_preview_url( $preview_url ); $this->assertEquals( $preview_url, $this->manager->get_return_url() ); $_SERVER['HTTP_REFERER'] = wp_slash( admin_url( 'customize.php' ) ); $this->assertEquals( $preview_url, $this->manager->get_return_url() ); // See #35355. $_SERVER['HTTP_REFERER'] = wp_slash( admin_url( 'wp-login.php' ) ); $this->assertEquals( $preview_url, $this->manager->get_return_url() ); $url = home_url( '/referred/' ); $_SERVER['HTTP_REFERER'] = wp_slash( $url ); $this->assertEquals( $url, $this->manager->get_return_url() ); $url = 'http://badreferer.example.com/'; $_SERVER['HTTP_REFERER'] = wp_slash( $url ); $this->assertNotEquals( $url, $this->manager->get_return_url() ); $this->assertEquals( $preview_url, $this->manager->get_return_url() ); $this->manager->set_return_url( admin_url( 'edit.php?trashed=1' ) ); $this->assertEquals( admin_url( 'edit.php' ), $this->manager->get_return_url() ); }
/** * Test get_return_url()/set_return_url() methods. * * @see WP_Customize_Manager::get_return_url() * @see WP_Customize_Manager::set_return_url() */ function test_return_url() { wp_set_current_user($this->factory->user->create(array('role' => 'author'))); $this->assertEquals(get_admin_url(), $this->manager->get_return_url()); wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); $this->assertTrue(current_user_can('edit_theme_options')); $this->assertEquals(admin_url('themes.php'), $this->manager->get_return_url()); $preview_url = home_url('/foo/'); $this->manager->set_preview_url($preview_url); $this->assertEquals($preview_url, $this->manager->get_return_url()); $this->manager->set_return_url(admin_url('edit.php?trashed=1')); $this->assertEquals(admin_url('edit.php'), $this->manager->get_return_url()); }
/** * Initialize the template Customizer feature class. * * @static * @since 0.4 * @access public * * @param WP_Customize_Manager $wp_customize Customizer instance. */ public static function init($wp_customize) { $self = new self(); $self->wp_customize = $wp_customize; do_action('amp_customizer_init', $self); // Settings need to be registered for regular customize requests as well (since save is handled there) $self->register_settings(); // Our custom panels only need to go for AMP Customizer requests though if (self::is_amp_customizer()) { if (empty($_GET['url'])) { $wp_customize->set_preview_url(amp_admin_get_preview_permalink()); } $self->_unregister_core_ui(); $self->register_ui(); } elseif (is_customize_preview()) { // Delay preview-specific actions until we're sure we're rendering an AMP page, since it's too early for `is_amp_endpoint()` here. add_action('pre_amp_render_post', array($self, 'init_preview')); } }