WordPress.org

Ready to get started?Download WordPress

Forums

1-click Retweet/Share/Like
wp_enqueue_style & wp_enqueue_script called incorrectly (3 posts)

  1. AlanP57
    Member
    Posted 1 year ago #

    As the WordPress error messages says, "Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks."

    That mean these functions should not be called directly but like so:

    function enqueue_my_scripts_and_styles() {
      wp_enqueue_style('thickbox');
      wp_enqueue_script('jquery');
      wp_enqueue_script('thickbox');
      wp_register_script('postmessagejs', LACANDS_PLUGIN_URL .'jquery.ba-postmessage.min.js');
      wp_enqueue_script('postmessagejs');
      wp_register_script('lacandsjs', LACANDS_PLUGIN_URL.'la-click-and-share.js');
      wp_enqueue_script ('lacandsjs');
      wp_register_style ('lacandsnetworkpubcss', LACANDS_PLUGIN_URL.'la-click-and-share-networkpub.css');
    		wp_enqueue_style  ('lacandsnetworkpubcss');
    
       wp_enqueue_style('special-offers-style', get_template_directory_uri() . '/functions/css/special-offers.css');
    
    }
    
    add_action( 'wp_enqueue_scripts', 'enqueue_my_scripts_and_styles' );

    in la-click-and-share.php arount line 1033.

    http://wordpress.org/extend/plugins/1-click-retweetsharelike/

  2. vivekpuri
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you for the tip. We will look into it.

  3. Dacus
    Member
    Posted 1 year ago #

    Hello guys!

    As I see that the "Plugin Author" didn't offered the solution for the problem described here i want to share my fix:

    Go to wp-content/plugins/1-click-retweetsharelike/la-click-and-share.php at the line approximately: 1022 and change the entire function lacands_main() with the following code:

    function thematic_enqueue_scripts() {
    	wp_enqueue_script('jquery');
    	wp_enqueue_script('thickbox');
    	wp_register_script('postmessagejs', LACANDS_PLUGIN_URL .'jquery.ba-postmessage.min.js');
    	wp_enqueue_script('postmessagejs');
    	wp_register_script('lacandsjs', LACANDS_PLUGIN_URL.'la-click-and-share.js');
    	wp_enqueue_script ('lacandsjs');
    }
    
    function thematic_enqueue_styles() {
    	wp_enqueue_style('thickbox');
    	wp_register_style('lacandsnetworkpubcss', LACANDS_PLUGIN_URL.'la-click-and-share-networkpub.css');
    	wp_enqueue_style('lacandsnetworkpubcss');
    }
    
    function lacands_main() {
    	lacands_init();
    	lacands_writeOptionsValuesToWPDatabase_twitter();
    	$dims = array('width' => 250, 'height' => 300);
    	$widget_ops = array('description' => LACANDS_FB_RECOMMENDATIONS_NAME);
    	register_activation_hook( __FILE__, 'lacands_activate' );
    	if ( is_admin() ) {
    		lacands_set_options();
    		lacandsnw_set_options();
    		add_action('wp_enqueue_styles', 'thematic_enqueue_styles');
    		add_action('wp_enqueue_scripts', 'thematic_enqueue_scripts');
    		add_action('admin_menu',  'lacands_wp_admin');
    		add_action('admin_menu',  'lacands_pages');
    		add_action('admin_notices', 'lacands_warning');
    		add_action('activate_{$plugin}', 'lacandsnw_pushpresscheck');
    		add_action('activated_plugin', 'lacandsnw_pushpresscheck');
    		wp_register_widget_control(LACANDS_FB_RECOMMENDATIONS_ID, LACANDS_FB_RECOMMENDATIONS_NAME, 'lacands_fb_recommendations_settings', $dims, $widget_ops);
    	}
    	add_filter ( 'the_content', 'lacands_wp_filter_post_content');
    	wp_register_sidebar_widget(LACANDS_FB_RECOMMENDATIONS_ID, LACANDS_FB_RECOMMENDATIONS_NAME, 'lacands_fb_recommendations', $widget_ops);
    	register_deactivation_hook( __FILE__, 'lacands_deactivate' );
    }

    This will fix both problems.

    P.S. Hope the Plugin Author will add this code to his plugin and I expect for his thanks :). Wish you the best!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.