Forum Replies Created

Viewing 15 replies - 31 through 45 (of 45 total)
  • MK

    (@mkarimzada)

    Hi there,

    I think when your onChange event fires, the callback calls useState with the new value, then it’s passed to your text field as a prop. At this point, React decided to render a new component, which is why you lose focus and edit() is called.

    I think you could use components keys, specially the form and the input itself. Keys let React components to keep its identity. You could read more here.

    I hope this helps.

    MK

    (@mkarimzada)

    Hi there,

    I think it’s better to keep the logo separate from navigation since logo needs organization schema if that makes sense and matters to you.

    Just wrap the logo with a div and put it right after wp_nav_menu() in your header/custom header, then you could style it however you want.

    To achieve the same looks as supplied UI, here is a small snippet using flexbox. https://postimg.cc/dZwZBspq

    <div class="parent-wrapper">
      <ul class="menu">
        <li>Home</li>
        <li>About</li>
        <li>Contact</li>
      </ul>
      <div class="logo">
        <img class="site-logo" src="" alt="">
      </div>
    </div>
    .parent-wrapper{
      background-color: #e7e7e7;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      
      .menu {
        list-style: none;
        
        li {
          display: inline-block;
          margin-right: 2rem;
        }
      }
    }
    MK

    (@mkarimzada)

    Hi there,

    You could read more about conditional tags here. Remember to hook the wrapper function of is_single after wp_query ran if you are using it in functions.php or give it a priority to run later.

    To do this in template files you could create custom query:
    $query = new WP_Query( array( 'post_type' => 'post' ) );

    You could check the post type in the loop:

    if( $query->have_posts() ) { 
        if( 'post' == $query->post_type ) {
        // Do something with single post
        }
    
        if( 'page' == $query->post_type ) {
        // Do something with single page
        }
    
        if( 'book' == $query->get_post_type() ) {
        // Do something with book post type
        }
    }

    Or you could create a function and give it a higher priority:

    function where_am_i()
    {
        if (is_single()) {
            // Do something with single post
        }
    
        if (is_page()) {
            // Do something with single page
        }
    }
    
    add_action('the_post', 'where_am_i', 135);

    You could create a post object and check by ID:

    function where_am_i($post_ID)
    {
        global $post;
        if ($post->ID == $post_ID) {
            // Do something here
        }
    }
    
    add_action('the_post', 'where_am_i', 135);
    MK

    (@mkarimzada)

    I think you misunderstood the point. He is using an API in his application and a cloud based mail service to send the emails. It’s not his web server/mail server. You could read more here.

    FYI If you want to send a custom mail using Mailchimp you have to do exactly the same by requiring Mailchimp PHP Class.

    The problem he has is with filtering the users based on available meta_value/meta_key and dynamically use their email address to send the email.

    MK

    (@mkarimzada)

    @corrinarusso I don’t see much difference between SMTPeter and Mailchimp. Both are third party APIs.

    As far as your concern about validation and best practices, both APIs and their PHP class is similar SMTPeter and Mailchimp. You could take a look yourself.

    I think the question here is how to conditionally send the email based on available data in database, not which API you want to call to send the email. Also, there are lots of plugins with way more customization, and I think it’s very practical.

    MK

    (@mkarimzada)

    I agree with Bcworkz and Corrina there are lots of downsides sending emails this way, but not the issues about reliability and delivery of the emails. SMTPeter is a reliable SMTP service to use and their API is pretty powerful specially when you want to create emails from JSON data.

    However to troubleshoot your function, I would start with $users object. It’s obvious wp_debug wouldn’t work because you have if statements to check if values exists which prevents from code errors. You should look into debugging your data with dumping the data, not code errors.

    Also, try to improve the WP_Query $args. In meta_query array you are passing $edition_id as number and comparing it as string. Try using other comparisons and dump the articles.

    It worths mentioning that there is a core new enhancement ticket open about unexpected behavior of filtering users with certain dynamic meta_key/value.

    Also, I would clean up the code and use $wpdb and INNER JOIN couple of queries to get the results instead of looping over and over on users and posts.

    I hope this helps!

    MK

    (@mkarimzada)

    I think you need to adjust your variable types. Once you set $user_has_already_voted to a string, then compare the values using string comparison, not empty function.

    In your case empty function checks if it exists or its value is false.

    However, you could adjust the condition to:

    if (empty($user_has_already_voted) || $user_has_already_voted == ''){}

    I hope this helps!

    MK

    (@mkarimzada)

    Hi there-

    All hyperlinks and inline-images in the post content needs to be manually updated to point to new domain. Or if you are a developer who is comfortable writing SQL queries, that’s another option too.

    MK

    (@mkarimzada)

    There are many different approaches you could take.

    I suggest lets name ID and value of checkboxes the same, then create an empty state array and pass the value of checked element to this array and save it as post meta hooked to save_post action, then get back the values with get_post_meta hooked to the_post action and finally with ajax pass the state array/object or saved post meta to jQuery and show or hide the <div>.

    This way you have checked elements in the db and available in JS for each post.

    I hope this helps.

    MK

    (@mkarimzada)

    Hi there-
    I like your third approach it seems easier to implement and what you could do is create a custom column on posts table and add support for filtering the posts.

    However, it worths to note that custom meta boxes feels a little slower and less functional with the block editor. I’ve done something similar in the past, where I wanted to create a custom meta query for posts with different priorities in categories archive, similar to sticky posts but with more complex meta query to filter them. What I ended up doing was creating a setting sidebar block and load categories via REST API and conditionally send back query results to pre_get_posts hook.

    I hope this helps!

    MK

    (@mkarimzada)

    @flaschenzug22 Here is a good article that shows how WP core loads and adjust the hook to load before or after theme load.
    EDIT: An alternative hook would be wp in your case.

    Also, you could adjust the priority where wp_enqueue_scripts is being hooked or remove it which will default to 10.

    • This reply was modified 3 years, 6 months ago by MK.
    MK

    (@mkarimzada)

    @flaschenzug22 Remember “wp_enqueue_scripts” action is being hooked to “wp_head”. I think a better approach would be separating the “require_once” and “wp_enqueue_scripts”:

    function load_custom_shortcode_scripts()
    {
        if (is_single(208)) {
          
            require_once("stroop/stroop.php");
            
            add_action('wp_enqueue_scripts', function() {
                wp_enqueue_script('gamescript_stroop', get_stylesheet_directory_uri() . '/assets/shortcodes/stroop/stroop.js', array('jquery'), wp_get_theme()->version, false);
                wp_localize_script('gamescript_stroop', 'ajaxLoad', array( 'ajaxUrl' => admin_url('admin-ajax.php')));
            }, 100);
        }
    }
    
    add_action('after_setup_theme', 'load_custom_shortcode_scripts');

    I hope this makes sense. Thank you!

    MK

    (@mkarimzada)

    Hi there,

    @flaschenzug22 The second version of your script works fine. The only issue I noticed is the script dependency array, it should be “jquery”.

    function load_custom_shortcode_scripts()
    {
        if (is_admin()) {
            return;
        }
        if (is_single('208')) {
            wp_register_script("gamescript_stroop", get_stylesheet_directory_uri() . '/assets/shortcodes/stroop/stroop.js', array('jquery'));
            wp_enqueue_script('gamescript_stroop');
            wp_localize_script('gamescript_stroop', 'ajaxLoad', array( 'ajaxUrl' => admin_url('admin-ajax.php')));
        }
    }
    add_action('wp_enqueue_scripts', 'load_custom_shortcode_scripts');
    • This reply was modified 3 years, 6 months ago by MK.
    MK

    (@mkarimzada)

    @mmakenzi Have you run tests on different browsers?

    MK

    (@mkarimzada)

    Since your logo is an image, the easiest solution would be creating a new header.php
    However, you could possibly update the img src with css:

    .custom-logo {
        content:url('https://yourwebsite.com/custom-logo.jpg');
    }

    Just remember to check browser support on content:url

    I hope this helps!

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