Forum Replies Created

Viewing 15 replies - 31 through 45 (of 151 total)
  • If you had opened up your browser’s dev console, you would see that there is an JS error. You are missing closing brackets:

    function form($instance) {
    
    		wp_enqueue_script('jquery-ui-accordion');
    	?>
    		<script>
    			jQuery(document).ready(function($) {
    				$('#accordion').accordion();
                            }); //missing brackets here
    		</script>
    
    		<div id="accordion">

    After that, it is working, though not displaying very nicely. You will need to play with the CSS or something because the accordion doesn’t fit the admin panel’s widget area somehow.

    Anyways, you are right about the no-access to functions.php, my mistake. There is a nice solution to this problem too.

    Ah, I see. Can’t the configuration be hardcoded into the plugin and only the additional configs passed as values in shortcode? Or are the configurations large?

    I have a problem with imagining what you are doing in that plugin. Never had to pass a large configs from the editor and if yes, used post meta keys or other UI types.

    In that case, use wp_localize_script function. For example, if I have a script going by the handle ‘lamosty-js-script’, I can pass data to it like this:

    wp_localize_script('lamosty-js-script', 'Lamosty_Data', array(
    	'key1' => array(
    		'key1-1' => 'value1-1',
    		'key1-2' => 'value1-2',
    		'key1-3' => array(
    			'key1-3-1' => 'value-1-3-1'
    		)
    	),
    	array(
    		'key2-1' => 'value2-1',
    		'key2-2' => array(
    			'key2-2-1' => 'value2-2-1'
    		)
    	)
    ) );
    // You need to call wp_localize_script before wp_enqueue_script for it to work.
    wp_enqueue_script( 'lamosty-js-script' );

    The array is converted into a standard JS object type. Screenshot.

    As I don’t have the source code of your widget, I can only give you a general advice.

    • When working with JS, always use Developer Console of your browser. You can detect JS errors or other messages there and also inspect HTML/CSS code easily.
    • Before you can use a JS library, it has to be loaded in the browser, otherwise you’ll receive JS undefined errors.

    Your widget is run after the function wp_head() has been called (=> after outputting the site header </head>), therefore wp_enqueue_script('jquery-ui-accordion'); outputs the accordion library in the footer of your site. However, your widget is run somewhere in the middle of the page and the accordion library has not yet been loaded into the browser (not yet outputted). If you inspect the Developer Console, you would observe an Uncaught TypeError: undefined is not a function.

    There are two options how to fix this:

    1. Enqueue the accordion library before the wp_head() is called. For example, in your functions.php, you could add a piece of code:

    function lamosty_enqueue_accordion() {
       wp_enqueue_script( 'jquery-ui-accordion' );
    }
    
    add_action( 'wp_enqueue_scripts', 'lamosty_enqueue_accordion' );

    which does the trick. Action wp_enqueue_scripts is run during wp_head() execution.

    2. If you want to enqueue the accordion library only on pages where the accordion is to be used, modify your JS code as shown below:

    jQuery(function($) {
    	$("#accordion").accordion();
    });

    which is the same as calling

    jQuery(document).ready(function($) {
       $("#accordion").accordion();
    });

    What it does is that jQuery waits until the page is “ready” (=> everything has been loaded) and runs the inner function only after that. In this case, it doesn’t matter that the accordion library is loaded in the footer of the page because jQuery is waiting till everything is loaded, only then executing the function. You can read more about it on jQuery docs site.

    You can encode the multidimensional array into JSON string and pass it to the shortcode. For example:

    Code below json_encode-s your assoc. array and prints it on a page. Copy-paste the output and continue with this guide.

    var_dump( json_encode( array(
    	'key1' => array(
    		'key1-1' => 'value1-1',
    		'key1-2' => 'value1-2',
    		'key1-3' => array(
    			'key1-3-1' => 'value-1-3-1'
    		)
    	),
    	array(
    		'key2-1' => 'value2-1',
    		'key2-2' => array(
    			'key2-2-1' => 'value2-2-1'
    		)
    	)
    ) ) );

    The code below is the shortcode which decodes the JSON input back into assoc. array.

    function lamosty_multiarray_shortcode_func( $atts ) {
    	var_dump( $atts ); // prints all $atts
    	$array =  json_decode( $atts['columns'], true ) // decodes your input from the shortcode
    }
    
    add_shortcode( 'lamosty_multiarray_shortcode', 'lamosty_multiarray_shortcode_func' );

    You need to be careful when inputting the encoded JSON string into the shortcode in WordPress as json_encode uses double quotes. For example:

    [lamosty_multiarray_shortcode key='{"key1":{"key1-1":"value1-1","key1-2":"value1-2","key1-3":{"key1-3-1":"value-1-3-1"}},"0":{"key2-1":"value2-1","key2-2":{"key2-2-1":"value2-2-1"}}}' another_key="10"]

    I had to use single quote ' in the shortcode.

    On the other hand, I don’t think this is a good way to pass data to your shortcodes. Why do you need to pass an associative array into it?

    Yes, the speed gains are the result of bypassing FastCGI server (in my case HHVM) and storing page cache in a tree-like structure directly on the RAM of the server.

    You can probably purge the cache from JS (rtcamp has a plugin for it), but once the request has been sent to the FastCGI server, it is run through all of WordPress functions and code, so purging the cache afterwards won’t help.

    As for caching all pages including of logged in users, I haven’t studied this yet, but had seen an article about this on Drupal forums. Maybe you can learn something from it.

    Hello Chuck,

    I don’t think it goes against any WordPress UI rules. WordPress ships with jQuery accordion out of the box. Just wp_enqueue_script('jquery-ui-accordion'); in your widget code and you are good to go.

    I don’t think it is a good idea to use the cache for logged in users and WooCommerce shopping cart pages.

    If you are using Nginx as your page caching tool, you can add a condition to skip page caching for these types of requests, for example:

    ##
    # FastCGI Caching
    ##
    
    set $skip_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
    	set $skip_cache 1;
    }
    if ($query_string != "") {
    	set $skip_cache 1;
    }   
    
    # Don't cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    	set $skip_cache 1;
    }   
    
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    	set $skip_cache 1;
    }
    
    # WooCommerce no caching
    
    if ($request_uri ~* "/<your-checkout-page>.*|/<your-cart-page>.*|/<your-account-page>.*") {
        set $skip_cache 1;
    }
    
    if ( $arg_add-to-cart != "" ) {
        set $skip_cache 1;
    }
    
    if ( $http_cookie ~* "woocommerce_items_in_cart" ) {
        set $skip_cache 1;
    }
    
    location / {
    	try_files $uri $uri/ /index.php?$args;
    }    
    
    location ~ \.php$ {
    	try_files $uri =404;
    	include fastcgi_params;
    	fastcgi_pass unix:/var/run/hhvm/hhvm.sock; # I'm using HHVM here
    
    	fastcgi_cache_bypass $skip_cache; # skip the cache if $skip_cache == 1
                fastcgi_no_cache $skip_cache;
    	fastcgi_cache WORDPRESS;
    	fastcgi_cache_valid  60m;
    }

    I just downloaded your plugin and the ‘Add Media’ button in each post or page is working fine on my end. Or do you mean some other ‘Add Media’ button?

    Btw, I’ve uncommented function hooking to the shutdown action hook in your plugin so I could test it.

    Forum: Hacks
    In reply to: Post type tree loop

    Hi NelutuO.

    Do you have any code to show?

    Yes you did. I’m sorry, I haven’t noticed it. Yeah, found it useful ??

    If I understand your problem correctly, you want to query the posts by post_type of single_release_post and meta_key of u365_artist_name with value of the name of currently viewing post.

    Well, you can get the current post title with get_the_title function. Then, pass this value into the meta_value filter in the WP_Query $args. For example:

    $post_title = get_the_title();
    
    $args = array(
    	'post_type'              => 'single_release_post',
    	'post_status'            => 'publish',
    	'pagination'             => false,
    	'posts_per_page'         => '3',
    	'posts_per_archive_page' => '7',
    	'ignore_sticky_posts'    => true,
    	'meta_key'               => 'u365_artist_name',
    	'meta_value'             => $post_title
    );

    I found a nice article about querying the DB using meta keys and values.

    Hi Vykerus,

    you need to widgetize your theme, if the theme doesn’t support it out of the box. Add new widget area above the slider. Style it with absolute positioning over the slider images.

    Inspecting the theme you pasted here (realty on themeforest) might help with the CSS and HTML you need to modify.

    With @tara’s solution, you can get the comments you need. Then use WP_List_Table to display the comments in a nice, WordPress-like format in your plugin.

    Nothing is happening? There should be a new item in the main navigation on the left side of the screen.

    When I added your code into my functions.php, it worked. See a screenshot

Viewing 15 replies - 31 through 45 (of 151 total)