• Resolved cpu21

    (@cpu21)


    I am a subscriber of WPBeginner website and YouTube.
    Recently I watched the “Insert Headers and Footers” plugin evolve into WPCode via WPBeginner YouTube. Thanks for making a great plugin.

    Here is a short php code snippet to change the wordpress logo when admin login.

    function my_login_logo() { ?>
    <style type="text/css">
    body.login div#login h1 a {background-image: url('https://fastreport.co.kr/wp-content/uploads/2022/07/auto_issue_logo.svg'); background-size: contain; width: 275px; height: 39px; margin-bottom: 32px;}
    </style>
    <?php }
    add_action( 'login_enqueue_scripts', 'my_login_logo' );

    Afterwards I changed the image address of https://fastreport.co.kr/wp-content/uploads/2022/07/auto_issue_logo.svg to https://cdn.fastreport.co.kr/fastreport/2022/07/22183728/auto_issue_logo.svg but it is not saved.

    I found that the same issue is occurring on both the Newspaper theme and the GeneratePress theme site.
    I tried disabling all plugins and changing to Twenty Twenty-Two theme, but still the same problem.
    WPCode will refuse to save if there is an image URL that is different from the site address. I found the same issue with other snippets related to image URLs.

    I don’t know if this only happens when the image address is different from the site domain, or if it always happens when a different address is in the snippet. But this seems to be an obvious bug.

    Please check. Thanks

    • This topic was modified 2 years, 3 months ago by cpu21.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cpu21,

    Thank you for your feedback, we’re happy you like the plugin.

    Can you please give us more details about what you mean when you say the snippet is not saved?
    Are you making changes to the snippet and after saving the code is the same as before or is the snippet not activating?

    Are you using version 2.0.1?

    Would it be possible to include a screenshot of your snippet to see how it is set up?

    Thanks

    • This reply was modified 2 years, 3 months ago by Mircea Sandu.
    Thread Starter cpu21

    (@cpu21)

    Yes I am using version 2.0.1.
    I linked the screenshot.
    Please check in order.

    1. Before Editing : https://pn-gp.viewus.co.kr/ss_WPCode1.jpg
    2. Editing : https://pn-gp.viewus.co.kr/ss_WPCode2.jpg
    3. After editing (after save) : https://pn-gp.viewus.co.kr/ss_WPCode3.jpg

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cpu21,

    Thank you for the details, can you please try the following steps to help troubleshoot this:

    1. Deactivate the snippet and save.
    2. Edit the image URL and save.
    3. Check if the changes are now stored & try reactivating the snippet.

    Thanks

    Thread Starter cpu21

    (@cpu21)

    it works fine!
    What is the problem, and why is this happening?

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cpu21,

    Thank you for confirming that.

    I suspect there is something in the code you have below that is preventing the snippet from updating correctly. If it’s possible to share the whole code I’d be happy to try figuring out what is causing it.

    Thanks

    Thread Starter cpu21

    (@cpu21)

    Here is full php snippets.

    // Admin Login Logo
    function my_login_logo() { ?>
    <style type="text/css">
    body.login div#login h1 a {background-image: url('https://fastreport.co.kr/wp-content/uploads/2022/07/auto_issue_logo.svg'); background-size: contain; width: 275px; height: 39px; margin-bottom: 32px;}
    </style>
    <?php }
    add_action( 'login_enqueue_scripts', 'my_login_logo' );
    
    // Admin Login Logo URL
    function custom_loginlogo_url($url) {
    	return 'https://fastreport.co.kr/';
    }
    add_filter( 'login_headerurl', 'custom_loginlogo_url' );
    
    // Admin Login Logo URL Title
    function my_login_logo_url_title() {
    	return 'Go to fastreport.co.kr';
    }
    add_filter( 'login_headertext', 'my_login_logo_url_title' );
    
    // Yoast SEO Facebook Meta - unsupported WebP : Adding the Open Graph in the Language Attributes
    function add_opengraph_doctype( $output ) {
            return $output . ' xmlns:og="https://opengraphprotocol.org/schema/" xmlns:fb="https://www.facebook.com/2008/fbml"';
        }
    add_filter('language_attributes', 'add_opengraph_doctype');
    
    // Yoast SEO Facebook Meta - unsupported WebP : Add Open Graph Meta Info
    function insert_fb_in_head() {
        global $post;
        if ( !is_singular()) //if it is not a post or a page
            return;
            // echo '<meta property="fb:app_id" content="Your Facebook App ID" />';
            // echo '<meta property="og:title" content="' . get_the_title() . '"/>';
            // echo '<meta property="og:type" content="article"/>';
    		// echo '<meta property="og:url" content="' . get_permalink() . '"/>';
            // echo '<meta property="og:site_name" content="Your Site NAME Goes HERE"/>';
    		if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
    			$default_image="https://fastreport.co.kr/wp-content/uploads/2022/07/auto_issue_home_featured_image.jpg";
    			echo '<meta property="og:image" content="' . $default_image . '"/>';
        	} else {
    			$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
            	if ( wp_get_image_mime( $thumbnail_src[0] ) == 'image/webp' ) {
    				echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
    				echo '<meta property="og:image:width" content="' . esc_attr( $thumbnail_src[1] ) . '"/>';
    				echo '<meta property="og:image:height" content="' . esc_attr( $thumbnail_src[2] ) . '"/>';
    				echo '<meta property="og:image:type" content="' . wp_get_image_mime( $thumbnail_src[0] ) . '"/>';
    				echo '<meta property="og:image:alt" content="' . get_the_title() . '"/>';
    			}
        	}
    	echo "";
    }
    add_action( 'wp_head', 'insert_fb_in_head', 5 );
    
    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cpu21,

    Thank you for sharing the full snippet.

    I can’t see anything in there that could cause that issue, it might be something specific to your setup from the theme or another plugin that might interfere.

    Is the updating issue still happening now if the snippet is active?

    Thread Starter cpu21

    (@cpu21)

    I found the plugin causing it!
    That plugin is WP Offload Media. If I disable this plugin, WPCode saved snippets normally.
    I am using WP Offload Media version 2.6.2, pro version.
    * Pro Version: https://deliciousbrains.com/wp-offload-media/
    I am currently serving images through Amazon CloudFront.
    I don’t know the exact reason, but WP Offload Media is definitely the cause.
    I took a screenshot of the WP Offload Media plugin options.
    https://pn-gp.viewus.co.kr/ss_Offload_Media_options.jpg

    And if I enable WP Offload Media and do not write https or http, WPCode also saves snippets normally.

    • This reply was modified 2 years, 3 months ago by cpu21.
    • This reply was modified 2 years, 3 months ago by cpu21.
    • This reply was modified 2 years, 3 months ago by cpu21.
    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cpu21,

    Thank you for looking into this further.
    I suspect in this case it’s a side-effect of the plugin replacing URLs and the way WPCode stores the data which is probably preventing that specific edit (the image URL).

    I made a note to look further into this to try and improve that behaviour.

    Thanks!

    Thread Starter cpu21

    (@cpu21)

    I’ll ask this to WP Offload Media as well.
    Mircea Sandu, thank you very much for your help.
    Regards

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘php snippet is not saved.’ is closed to new replies.