Hot answers tagged

7

For this example lets say we have the following do_action('bt_custom_action', get_the_ID(), get_the_title(), get_the_content()); The arguments that will be passed to add_action would be in this order the post id the post title the post content By default if we hook into our do_action without any arguments, like this add_action('bt_custom_action', '...


5

Everything Butterend_Toast says is correct, but I want to touch on why it works that way. Under the hood, do_action() and apply_filters() are just calling the core PHP function call_user_func_array(). When you run add_action() you are storing a reference to a callable, with a number representing how many arguments that function accepts. add_action( '...


4

When you include wp-load.php, WordPress will load wp-config.php, where constants with the same identifiers you have chosen here are already defined. This should be throwing warnings regarding the duplicate definition. Because you cannot re-define constants, the values you are attempting to set in this file are ignored. Choose different names for them if they ...


4

If you want to receive only linkbacks from your own WordPress site, then try both of these: But if you want to allow all that were sent as trackbacks (where the comment type is trackback), then just ignore the second snippet below, which I added because in default/core themes like Twenty Twenty-One, both pingbacks and trackbacks would each appear as a "...


4

As said on https://wordpress.org/support/article/debugging-in-wordpress/#example-wp-config-php-for-debugging: (note though, the "blogging" below is now "publishing") NOTE: You must insert this BEFORE /* That's all, stop editing! Happy blogging. */ in the wp-config.php file. So just put it there, like this: define( 'WP_DEBUG', true ); /*...


3

Where is the problem? Am I doing something wrong? Your code seems fine to me, so despite I can't give you a definitive answer on what/where exactly is the problem, I thought these might help you troubleshoot the issue: First and foremost, check your configuration — e.g. did you use the correct (SMTP) username/email, password, host? And make sure the ...


3

Can they theoretically develop a WP plugin to access the files (or even WP config, including DB credentials) of another WP installation? Yes. If your folders are owned by the same user, run as the same user in Apache/Nginx or have read/write access to each other, then it's possible. Your installations are sandboxed at the server/host level, not the WP level....


3

What I would like to do is, when the user unselects all the terms in the filter it displays all the posts of my Custom Posts Type. In that case, then make the tax query optional: // In mysite_filter_function(), define $args like so: $tax_query = array( 'relation' => 'AND' ); if ( ! empty( $groups_terms ) ) { $tax_query[] = array( 'taxonomy' ...


3

The conditional first checks against what gets returned from the template_include hook. In most cases, a template will be found, and there will be no issue. We'll only move onto the 2nd conditional if template_include cannot find or cannot load the template. We then look at the WP_Theme object, which does some base-line checks to see if something is wrong ...


3

Yes it is unsafe, though not for the reasons you think. DO NOT DO THIS. If your developers can upload a PHP file to your site that gets executed, then that PHP file can undo all other security measures that you put in place. The location of the file is irrelevant. Functionally, there is no difference from editing plugins directly. Additionally, a common ...


3

Now I have familiarized myself with the above principles via the documentation and I think I have understood them now I don't know which documentation you read, but you should check the Plugin Security section in the plugin developer's handbook. And there are three main issues I noticed in your code: Before attempting to use a $_GET or $_POST variable, you ...


3

I agreed with @PatJ — you should check if get_queried_object() returns an object or not. But you could simplify your code by simply using is_category() and in_category() which are conditional tags in WordPress: if ( is_category( 3 ) || in_category( 'arta' ) ) { wp_enqueue_style( 'twentytwenty-style-2', get_stylesheet_directory_uri() . '/style-arta.css', ...


3

There is indeed an unwanted ; (semicolon) in your function (try to look at line 99 in the twentytwentyone-child/functions.php file) which likely is the cause to the syntax error. So just remove that ; and the error would be gone: function my_service_template_footer_data() { echo "<script type='application/ld+json'> { '@context': 'https://...


3

I would suggest first read the wordpress documentation about actions to understand how they work. Actions are aplit into two section, add_action and do_action do_action is the "location" where you hook into it. A basic example of do_action do_action('my_custom_action'); You can also pass arguments into do_action which can be available in ...


3

Shouldn't the 2nd argument be a function? The second argument should be a value of type callable. callables are a fundamental type in PHP. E.g. these are some valid callables: Value Equivalent 'test' test() [ $obj, 'test' ] $obj->test() [ 'foo', 'bar' ] foo::bar() function() {...} or closure $foo = function(){...}; $foo(); And so on, see the ...


3

Sure You could use in_array for this type of check, something like this if (in_array($string, ['apple', 'banana', 'kiwi'])) { // keep adding as many as you need $Detail = false; $bShowNew = true; } If your array gets to big you can create a variable that will contain that array $allowed = [ 'apple', 'banana', 'kiwi' // etc... ]; if ...


3

Look at your condition at the end: if ( $result == false ) { wp_send_json_success( 'Link has been created' ); } else { wp_send_json_error(); } wpdb::insert() returns false when there's an error, so you're only returning a success response when there's an error. You need to swap the statement around. if ( $result == false ) { wp_send_json_error();...


3

That's not how <noscript> tags work, and if they did your usage is incorrect. The <noscript> tag defines an alternate content to be displayed to users that have disabled scripts in their browser or have a browser that doesn't support script. The <noscript> element can be used in both <head> and <body>. When used inside <head&...


3

You could try changing the output type of get_results() to ARRAY_A or ARRAY_N and see what kind of array they give you. E.g. $tables = $wpdb->get_results("show tables like 'pro_hist%'", ARRAY_A); var_dump($tables); foreach( $tables as $table ) { var_dump($table); } If $table is an array and it has the name as the first value, then get the ...


3

It doesn’t. You’ve written the PHP tag incorrectly, so your code is being printed to the browser instead of being run. You have <php?. It’s supposed to be <?php.


2

On a system where you can't change the /usr/bin/php symlink you can't change the PATH to point to a different version (because the php executables don't reside in distinct /lib/ directories) WP_CLI_PHP has no effect (like my Arch Linux with php(8), php7 installed from extra and wp-cli installed from AUR. I'm using php7 vs php8 here, but this should work ...


2

If you want to disable media pages completely, you should use a 404 response code instead of redirection. This can be done with the following code: function wpse237762_set_404() { if (is_attachment()) { global $wp_query; $wp_query->set_404(); status_header(404); } } // This will show 404 on the attachment page add_filter('...


2

A little bit faster than receiving the object and echo the term ID afterwards is to directly use get_queried_object_id().


2

<?php $downloads = $product->get_files(); foreach( $downloads as $key => $download ) { echo '<p class="download-link"><a href="' . esc_url( $download['file'] ) . '">' . $download['name'] . '</a></p>'; } ?> Check this.. Worked for me.


2

If you are using docker-compose and the WORDPRESS_EXTRA_CONFIG as I was, when I stumbled across that error, the solution would be to use double-dollar-sign notation as described in a corresponding issue in the docker-compose repo on GitHub. This additional environment variable is described in the "How to use this image" of the official image ...


2

I know this is an old topic but destroy_all() will destroy all sessions but destroy_others() destroys all sessions except the current session Destroy all sessions: $sessions = WP_Session_Tokens::get_instance( $user_id ); $sessions->destroy_all(); Destroy all sessions (except current session): $sessions = WP_Session_Tokens::get_instance( $user_id ); $...


2

The solution that was provided here did not work for me. It seems that the order items are assigned to the order after the woocommerce_new_order hook is triggered. I only managed to sort my issues after I changed the hook to woocommerce_checkout_order_processed as per below: add_action( 'woocommerce_checkout_order_processed', 'get_order_items_on_checkout', ...


2

You should change them. Its good practice to periodically change your wordpress salts. It will not affect the passwords in the database but it will log out all users.


2

I don't believe this is an issue with a WP update, but rather an issue that has always been there but unnoticed: $page = get_query_var('page'); page is a query var, yet it's being reused. As a result, when you ask for page 2, you are not asking for page 2 of the custom results, that's just a coincidence. Instead you are asking for page 2 of the main query, ...


2

Your server runs with a PHP version that doesn't support create_function. From the PHP manual about create function Warning This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. If you are using PHP 5.3.0 or newer a native anonymous function should be used instead. If the plugin is ...


Only top voted, non community-wiki answers of a minimum length are eligible