New answers tagged

0

You're not too far off in your thinking. Ideally though, you will want to use add_filter to change the value that My_User::login_page_url() returns. Taking your above example, say we have a class called My_User, and the method login_page_url (ie My_User::login_page_url() as given in the example link) looking like this: Class My_User { /** * ...


0

It really depends on what you're doing, but I agree in most cases using the settings API and running the code/instantiate the classes only when needed inside the callback is usually the best route to take opposed to instantiate everything upfront. Aside from the suggestions above - One approach I've taken a few times is hooking into some of the dynamic ...


0

The example in Settings API documentation uses admin_init and admin_menu for registering custom settings and admin pages. https://developer.wordpress.org/plugins/settings/custom-settings-page/ There's also an old Codex entry on actions typically run on front and back end requests, which can help pick a suitable action hook. https://codex.wordpress.org/...


0

For me, I offer you a solution composed of three parts: 1 - Create a CTP. 2 - Create the necessary javascript and css scripts. 3 - Create a dedicated template in the root of your theme archive-$posttype.php, in our example will be archive-product.php I created a repo in my git where you can download the Plugin here is the link: Custom CPT The source ...


0

Rather than just no-indexing the Page, 301 redirect it. This can be done either by server config (.htaccess, NGINX rules, etc.) or using a plugin. That way no one can actually get to the Page all on its own - it only exists on the front page.


2

Bitwise operators expect conditionals on either side of them to evaluate to either TRUE or FALSE. If FALSE it checks the next conditional until it finds a TRUE or all conditionals have been checked. Also, the is_page() function doesn't allow parameters to be passed in on a bitwise basis. So simply change your code to the below and you're good! <?php if ( ...


0

If you're set to a static front page, why would there be pagination? The proper way to have a paginated grid of posts as your front page is to set the homepage to "Your latest posts". You would then develop your front-page.php, home.php or index.php template to display posts as a grid (use the Template Hierarchy to determine which file you need). In that ...


0

I want to understand if I can write my own templates using only the conditional tags, or if i need to maintain the actual structure of the templates that include a lot of do_action() and less markup, I've not modified them, just copied inside the mytheme/woocommerce/ folder of my theme for now. WooCommerce extensions all make extensive use of those ...


1

To answer your second question you'll have to properly enqueue the Bootstrap 4 styles and scripts: Including CSS & JavaScript | Theme Development From there you either have to add existing WooCommerce classes to your BootStrap CSS or add BootStrap classes to your WooCommerce templates (preferred/recommended). As for the templates, it really depends on ...


1

One option could be to use data attributes on the entires listed on pages one and two. Then attach a click event that reads the attribute value on click saves it to localStorage. This way you wouldn't need to make an extra db call on page three. In the loop the data attribute value can come basically from anywhere. E.g. post meta, some post field, taxonomy ...


0

You should be able to get the current index in loop from the global $wp_query object. With the help of modulo you can then set an alternating css class for a post. global $wp_query; while ( have_posts() ) { the_post(); $alignment = ( ($wp_query->current_post + 1) % 2 === 0 ) ? 'even align-right': 'odd align-left'; // post html markup with class="&...


0

To set the default value for the category dropdown, you need to pass it as a parameter for the function. Like so, $dropdown_args = array( 'selected' => 2, ); wp_dropdown_categories( $dropdown_args );


0

You can use add_shortcode function to register a custom shortcode for your site. For example like this, // add to (child) theme's functions.php function my_download_featured_image_link( $atts, $content = '' ) { // shortcode should return its output return sprintf( '<a class="download_image" href="%s">%s</a>', // html output of the ...


1

In my experience with woocommerce, there are two ways. 1 - Add some extra css to your current theme. For example I want to modify the title of the product : I open the chrome inspector, I see that the product page has a class css for body.single-product. The product container has a class css div.product (create by woocommerce itself <div id = "...


1

I got it to work ! Yey! The answer lay somewhere in the General settings of the wp-admin site and my dyn account. I delted my dyn record from their site temporarely. Then I edited the configuration of my wordpress-site and folder in wp-admin. I changed it to the external IP and then it worked without index.php right away. Then I changed the values back to ...


0

Use this query to display woocommerce featured product and replace with yours $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( 'key' => '_featured', 'value' => 'yes' ); $featured = array( 'post_type' => 'product', 'stock' => 1, 'showposts' => 6, 'orderby' => 'date', ...


2

Is this normal behaviour? Yes. On a default Apache install, only index.html is set as the DirectoryIndex (the default setting). Either in the appropriate <VirtualHost> container, or main server config you need to add a <Directory> section that specifically targets the defined document root directory. For example: DocumentRoot /var/www/html &...


1

Follow This and Make sure Your Shop or which page you want for default Home page and Then Save Button. Thanks


0

You can change your "reading Settings" in Settings menu, Please select "Your home page displays" = check to a static page and select shop from the dropdown menu. after these changes your index page will be shop page.


0

Wordpress stores three levels of stock information on the wp_postmeta. Each product has manage stock enabled Stock Quantity Stock Status Since the products on the above questions were imported, few of them didn't had manage stock enabled so updating the stock quantity to 0 didn't work well. Solution: I forcefully updated the manage stock to be yes and ...


0

If I'm understanding your question correctly, you want links on your site to dynamically change depending on the domain name of the environment you're in? To do this you can replace any hard coded links with the home_url() function. So you would change references to links from http://192.168.0.1/your/path/here to <?php home_url(/your/path/here); ?> ...


0

If the GPX file is attached to the current page you can find it with get_attached_media(), e.g. $gpx_files = get_attached_media( 'application/gpx+xml' ); if ( count( $gpx_files ) >= 1 ) { echo do_shortcode ('[sgpx gpx="' . wp_get_attachment_url( $gpx_files[0]->ID ) . '"]'); } else { echo '<p class="warning">No GPX file attached!</p>...


0

I believe plugins are loaded before the theme (see here "plugins_loaded" vs "setup_theme") so the error is occurring because Helper has not loaded yet. One thing you can try is to create a child theme and add the class override there (via functions.php). You can also provide your override after the theme has loaded by hooking into "after_theme_setup" or "...


0

I updated only those parts which leads to explain the things which I was trying to tell you in my first answer. plugin-name.php define("PLUGIN_DIR_PATH",plugin_dir_path(__FILE__)); add_action( 'admin_menu', 'wim_register_my_custom_menu_page' ); function wim_register_my_custom_menu_page() { add_menu_page( __( 'Plugin name', 'textdomain' ), ...


2

The do_shortcode() function is currently in the foreach loop. I don't know what are the parameters of this shortcode , but if it accepts comma separated values of term slugs: $terms = get_the_terms( $post->ID , 'shoptype' ); $i=1; $commaSeparatedvalues=""; foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'shoptype' ); if( ...


2

get_the_category() retrieves the current post categories. To get all categories you should use get_categories() instead


1

I already had this need, I found this code somewhere in the web. up to you to customize it with your needs. I tested it on the Twenty Nineteen theme: Put this in functions.php : class themeslug_walker_nav_menu extends Walker_Nav_Menu { // add classes to ul sub-menus function start_lvl(&$output, $depth) { // depth dependent classes $indent = (...


0

You can divide the cities using explode function of php. It convert the strings to array on base of character added in the parameter. You can split the string on base of comma and print the location separately. Please use explode(",",$locations); However, you can also use repeater field of acf. In this way users can add as many field as they wants. Please ...


0

I am speculating here after reviewing your logic/comments above, yet let's try as follows Possible issue: During login, although you are setting the auth cookie, you are not setting the current user and this is potentially the cause of the break-down upon logout due to is_user_logged_in returning a false-positive/negative result. Possible resolution: In ...


2

This is because you're not adding elements to the array. You're overwriting them: $modified_result = array(); foreach($queryresult as $result){ $modified_result['name'] = $result->name; $modified_result['address'] = $result->address; } Your loop is setting the name and address property of the $modified_result array directly, and then ...


0

Even though you are echoing the shortcode, I think you still need to echo the ACF field inside the string of the do_shortcode function. Change your ACF field return function for the_field() : <?php echo do_shortcode("[tnc-pdf-viewer-iframe file=".the_field('document_link')." width="900px" height="700px" download="false" print="false" fullscreen="true" ...


0

Varnish was the problem. Varnish removes cookies from the response. That's why it didn't work in our case!


0

It looks that a reference to global $post; is missing at the beginning of your function widget(){}


0

First: There are no Errors, only Warnings in the W3C-Validator for your site. You should check if you can remove them, but they don't "break" your site. The First Console Error wants you to fix the Google Font: The Font name to be used is "Assistant" not "assistant". Don't know if you can fix this yourself as you use a Premium Theme. The second console ...


0

Check This Code: $demo_string = "The Godfather: Part II"; $demo_string = str_replace(':', '', $demo_string); $demo_string = str_replace(' ', '', $demo_string); output : TheGodfatherPartII


0

Add a new URL using add_submenu_page (without any parent assigned) and post your form data on that URL. Refer to this page for adding sub-menu page. Also, you should not send form data on any PHP file like this. This, will opens up your plugin for external attacks. Let, know if you unable to figure out the way of doint this. Have a Good Day!


1

Yes, as a best practice, you should call wp_current_user() because you can't assume that $current_user is set (or if it is set correctly with the user you're after). Of course, there's a third option that's only just sprung to mind... test whether $current_user is already set/defined and if it isn't, call wp_get_current_user(). Actually, that's kind ...


0

No, constructors should not define hooks. Constructors should be used to set the initial state of the object. Hooks have nothing to do with the object's initial state, so they don't belong in the constructor. Constructors should not have "side effects", so that using new ClassName() does not affect any other parts of the program, which is what registering ...


-1

it depends on what you want to do. for example, suppose your plugin needs javascript for it to work. in this case, we can enqueue the javascript in the constructor of the Class : class My_Plugin{ function __construct (){ add_action( 'wp_enqueue_scripts', array( $this , 'my_script' ) ); } function my_script(){ // here ...


-1

First, your question is purely PHP, I do not see a relationship with WordPress. If you want to link the two variables, you must use what is called: Passing by reference In your case : $first = & $second


0

The following WordPress actions are able to filter your code from all HTML comments. Place the PHP code into your functions.php file inside the WordPress theme directory. function callback($buffer) { $buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer); return $buffer; } function buffer_start() { ob_start("callback"); } function ...


0

You should look at the add_user_meta function to capture the info from the user. Then you can lookup the value using get_user_meta. Use this link for more info: https://developer.wordpress.org/reference/functions/add_user_meta/


0

This is the solution: add_action('pre_post_update', function($post_id, $post_data) { global $original_post; $original_post = get_post($post_id); }, 10, 2); add_action( 'save_post_', function($post_id, $post, $update) { global $original_post; $original_post->post_title; // original post title $post->post_title; // new post title }...


0

At first I will notice that logging in with the username only sounds like a insecure solution . You should not display the form in the init action hook. Add form display function to the action hook from checkout page (e.g. woocommerce_before_checkout_form) or overwrite the checkout template in the active theme and insert the form there. if ( ! ...


0

I've found a solution by myself! With two lines of code I'm now able to save all the selected images and then retrive them on the front-end. I have added an array in the JS code part: // media library script (function($){ $(document).ready(function(){ $(document).on('click', '.upload_image_button', function(e){ e.preventDefault(); var ...


0

Try this function pen_post_sidebar_twitter() { printf( '<input type="text" name="twitter_handler" value="%s" placeholder="Twitter handler" /> <p class="description">Enter twitter handler without the @ sign.</p>', esc_attr( get_option( 'twitter_handler' ) ) ); } Thanks


0

Since Simple Fields has been removed from the plugin directory you should consider recreating the custom fields using Advanced Custom Fields (ACF) or similar and then modifying the template to use the new fields. Keep the field names the same when you register them and it should be a pretty simple fix.


0

<?php global $wpdb; $limit = 0; $year_prev = null; $months = $wpdb->get_results( "SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'newses' GROUP BY month , year ORDER BY post_date DESC" ); ...


0

You need to set the auth cookie after wp_signon. Add this code and try and let me know the result. $user = wp_signon( $creds, false ); $userID = $user->ID; wp_set_current_user( $userID, $creds['user_login'] ); wp_set_auth_cookie( $userID, true, false ); do_action( 'wp_login',$creds['user_login'] );


0

You can try this action. Put this line into your active theme functions.php file remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );


Top 50 recent answers are included