Skip to main content

Questions tagged [php]

For questions about the server-side programming language that the WordPress core, plugins and themes are written in. Questions about using PHP outside a WordPress context are off-topic but might be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
7 votes
1 answer
46k views

How to get Woocommerce order product info

I am trying to get all woocommerce orders and find info about the products in each order. I have seen many examples on here and elsewhere on the web and they all seem to say to do the same thing but ...
geoffs3310's user avatar
7 votes
1 answer
1k views

Decrease file size upload in Media

By default, I have a 2m limit of uploads. I want to decrease this number. I found out that this code: function custom_file_max_upload_size( $file ) { $size = $file['size']; if ( $size > ...
Amanda Bynes's user avatar
7 votes
3 answers
6k views

Dynamically add id to heading tags

How do I add an id attribute dynamically to every heading tag on a wordpress website using php? I wanted to make it so that for every heading tag (h1, h2, h3, h4, h5, h6) I have a unique id attached ...
nwong212's user avatar
7 votes
3 answers
22k views

How do I directly access a PHP file located in my themes folder?

I have a file in my theme's folder called "test.php". If I go to www.mysite.com/wp-content/themes/my-theme/folder/test.php the theme loads which I assume is a 404 error handled by WP. If I change the ...
Gazillion's user avatar
  • 317
7 votes
1 answer
2k views

Wordpress Admin Bar pushed Sticky Footer off the bottom of the page

I've implemented Ryan Fait's oh-so-common sticky footer in a custom Wordpress theme. I've noticed now if I implement the Wordpress Admin Bar into my pages, which is 28px high (in current Wordpress ...
Jake Wilson's user avatar
7 votes
1 answer
6k views

WordPress "phpmailer_init" not working for me

I add the following code to the functions.php file. add_action( 'phpmailer_init', 'my_phpmailer_example' ); function my_phpmailer_example( $phpmailer ) { $phpmailer->isSMTP(); $...
km onur's user avatar
  • 129
7 votes
3 answers
353 views

How can I prevent a plugin from updating unless it's minimum PHP version is met?

I have a plugin distributed on WordPress.org that is fairly popular. I have to drop support for PHP 5.2and I'd like to at least drop support for PHP 5.2, but if I could make the minimum PHP 5.4, late ...
JPollock's user avatar
  • 1,248
7 votes
1 answer
6k views

Adding "Remember Me" in custom login

im currently using an ajax login i found here: http://wpsites.org/wordpress-ajax-login-and-register-without-a-plugin-10835/ Everything works perfectly fine. However i'd like to add a "REMEMBER ME" ...
Archangel17's user avatar
7 votes
1 answer
8k views

Show the most popular post per week

The plugin Most Popular Posts doesn't support WPML and therefore I have tried creating my own. I have found this tutorial in creating your own code for showing the most popular posts on my site: How ...
Philip's user avatar
  • 207
7 votes
1 answer
7k views

Ajax Load More Posts in Category Page

I am developing a theme where I need to load more posts with ajax. Currently, when I click load more on the category pages, all the posts are loading. The category.php looks like this : ` ...
Ranjan Agarwal's user avatar
7 votes
2 answers
9k views

why is translation not working on theme?

Background I am using the theme Rookie from Sportpress. I created a child theme. Translation files are existing, especially german in my case. Wordpress is set to german language. The Problem ...
André Kelling's user avatar
7 votes
5 answers
2k views

Remove option to allow trackbacks/pingbacks from post page options

I'm trying to disable all functionality related to pingbacks/trackbacks in WordPress and so far I have this: add_action( 'pre_ping', 'disable_pingback' ); function disable_pingback( &$links ) { ...
Brett's user avatar
  • 414
6 votes
6 answers
21k views

__(): What if I have to pass in a variable?

In the docs for the translate function __( $text, $domain ), it states that you must put the string directly in place of $text, that you cannot do something clever such as __( $my_text, 'text-domain' )...
geoff's user avatar
  • 185
6 votes
4 answers
642 views

Cleaning up WordPress to improve performance?

Looking over the current WordPress codebase it's clear that functions are over-used. My count is over 8,100 functions/methods are defined inside the WordPress codebase. That is terrible, and a ...
Xeoncross's user avatar
  • 213
6 votes
4 answers
30k views

Multisite get_home_url(); - Getting URL for current site

What would be the replacement for get_home_url() when using a multisite? For example, if I have one theme installed across several sites, and within the theme there are links that need to be specific ...
Tim McClure's user avatar
6 votes
3 answers
28k views

Displaying Logged-In User Name in Wordpress Menu

I'm using Wordpress with UserPro, and want my menu to display the logged-in user's first name, linked to the user profile page. The problem is that in my menu structure, the "Profile" menu option is ...
Akash kapur's user avatar
6 votes
2 answers
23k views

What does the token %1$s in WordPress represent [closed]

I have seen the token %1$ and similar ones more often in the WordPress code lately, but I can't figure out what it means. Here an example: sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), Does ...
Martin's user avatar
  • 97
6 votes
3 answers
9k views

Does an activated plugin automatically mean its methods are available to other WP functions?

I made a WordPress plugin like this: Class MY_CLASS { //codes } Global $myclass; $myclass = New MY_CLASS (); After installed and activated the plugin, can I use this class in other plugins without ...
Jenny's user avatar
  • 1,757
6 votes
3 answers
17k views

Add a Jquery Datepicker to custom field in post edit

I would like to add a custom field that is set by a jquery datepicker ui in the post edit panel. Im new to wordpress, so Im not sure how to go about adding something like this. I haven't had much luck ...
Thomas 's user avatar
  • 203
6 votes
6 answers
17k views

How to get the active theme's slug?

I'm able to get certain info about the active theme using wp_get_theme(). For example: $theme = wp_get_theme(); echo $theme->get( 'TextDomain' ); // twentyfifteen echo $theme->get( 'ThemeURI' );...
henrywright's user avatar
  • 3,067
6 votes
2 answers
21k views

Proper use of Output Buffer

I'm attempting to use actions to override function calls I currently have throughout a template (to make updating certain replicated sections easier). For example, in archives.php I have the following:...
Zach's user avatar
  • 1,923
6 votes
1 answer
41k views

PHP Catchable fatal error: Object of class WP_Error could not be converted to string

I need help with this: PHP Catchable fatal error: Object of class WP_Error could not be converted to string in /hosting/www/ortopediairati.es/public/wp-content/themes/irati/rt-framework/...
Sergi's user avatar
  • 63
6 votes
1 answer
10k views

Menu Items Disappearing

I'm running WP 3.5.1 and I've a menu with about 100 items. When I add new items to the menu older ones disappear. I'm not running Suhosin or similar stuff. What can be the cause? Note: I'm on a ...
Herr's user avatar
  • 163
6 votes
3 answers
9k views

How to change the wp-login.php page title?

I've been using the document_title_parts hook to change the page title for some front end pages. However, this doesn't seem to work for the login, register and password management pages. How can I ...
henrywright's user avatar
  • 3,067
6 votes
3 answers
41k views

How to properly insert data into custom table via plugin

I have a plugin that reads data from an uploaded file and runs queries on the wp database. These inserts are into a table created by my plugin, so they aren't the post type. This is how I got it ...
Breno's user avatar
  • 163
6 votes
5 answers
10k views

Where to get information about array fields in $_REQUEST?

I just started to learn PHP and doing things with WordPress and I am a bit confused about information in Codex. Was told that Codex got all info I required but I got stuck with it. What array fields ...
Rafal's user avatar
  • 61
6 votes
1 answer
18k views

Is it safe to use $_SERVER['REQUEST_URI']?

I've looked at other answers and I see that $_SERVER['REQUEST_URI'] is usually recommended and is the accepted answer for getting the current page URI along with $_SERVER['HTTP_HOST']. I looked at ...
Firsh - justifiedgrid.com's user avatar
6 votes
1 answer
12k views

Run WP-CLI using PHP

I've installed WP-CLI on the Mac and my next step is to execute WP-CLI commands using PHP script. I've tried to implement it the following way but I do not see anything happening. Can someone please ...
WKL's user avatar
  • 63
6 votes
1 answer
32k views

exclude multiple terms using get_terms() function

I am using this function to filter category terms from a calendar: $terms = get_terms( TribeEvents::TAXONOMY, array( 'orderby' => 'name', 'order' => 'ASC','exclude' => array(77)) ); ...
Verneet Singh's user avatar
6 votes
2 answers
5k views

How to serialize a Gutenberg block from block attributes in PHP?

I am writing a migration script which has to read the post_content of posts and then dynamically change some attributes of some custom Gutenberg blocks. I was able to read the post_content and then ...
Sudar's user avatar
  • 809
6 votes
1 answer
9k views

Woocommerce get selected shipping zone id for the current user

How can I get the selected shipping zone ID based on the current user in WooCommerce? I tried the code below, but I didn't get the zoneID from the cart page: $bh_packages = $cart->...
Nikko Dela Cruz's user avatar
6 votes
2 answers
6k views

Confirmation box when submitting post for review

A very common issue that I experience with new authors is that they forget to complete a few essential tasks prior to submitting their post for review (even though I have a guide available for them). ...
Christine Cooper's user avatar
  • 8,798
6 votes
2 answers
16k views

List of all theme customizer control types?

I have been looking through the theme customization API documentation and google to simply find out the names of the control types already built in to the theme customizer. More specifically I am ...
user1632018's user avatar
6 votes
2 answers
10k views

Wordpress Warning: preg_replace(): JIT compilation failed: no more memory

I just have installed xampp with php 7.3.1 on mac with OS El capitan. The problem that when i run a WordPress project will show: Warning: preg_replace(): JIT compilation failed: no more memory in ...
A.Alshaikhli's user avatar
6 votes
2 answers
21k views

Modify previous and next text from pagination links

I set the pagination parameters in functions.php and echoed where I want the links to appear, so far so good. The problem is that the previous and next texts are not modifying. I put a random text to ...
Gabriel Souza's user avatar
6 votes
2 answers
13k views

How can I call WordPress core functions in external scripts?

I'm trying to develop a code to call some Codex functions (https://codex.wordpress.org/Function_Reference) the problem is simple, I don't find any doc where read about how to start. I have a PHP ...
Leonardo Cavani's user avatar
6 votes
1 answer
2k views

Autoloading in Child Theme

I'm trying to autoload the vendor/autoload.php from my parent theme into my child theme. heres what i have tried but to no avail: function beast_theme_setup() { $var1 = get_theme_root_uri() . '/...
Henshall's user avatar
  • 113
6 votes
4 answers
683 views

Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]

I'm new to PHP, but I've noticed just about every PHP file has a security snippet, "Die if not accessed in the correct manner" script at the beginning; my question, does a child-theme functions.php ...
CSS Apprentice's user avatar
6 votes
1 answer
13k views

Allow only 1 taxonomy per custom post type [duplicate]

Wordpress allows Admin to select more than one category for a post , I would like to change that so user is allowed to select only 1 category for a custom post type. Please note I cannot remove ...
June's user avatar
  • 191
6 votes
3 answers
12k views

is it possible to run some php code within a wordpress page?

I'd like to access a DB table and render it in some data grid format using php on a dedicated wordpress page, accessible to members of a certain group. Is this at all possible with wordpress or is ...
fduff's user avatar
  • 161
6 votes
4 answers
923 views

How do you code for WordPress?

In plain php and frameworks coding is done with the help of IDE tools, im using PhpStorm and very happy so far, recently i decided to discover most popular CMS this days and got confused how do you ...
Umren's user avatar
  • 163
6 votes
2 answers
9k views

Preserve custom URL parameter on more pages

I created a custom URL parameter for sorting posts by their vote scores. I have a "most voted" link that sends a ?sort=most_voted URL paramater and using a query posts filter I display posts with most ...
wpStudent's user avatar
  • 141
6 votes
2 answers
6k views

Update Multiple Post Meta for the Same Post In One call?

How can I update multiple fields/Custom fields for the same post using only one call? Everything I came across are cases of multiple calls of "update_post_meta", for each of the fields. Is ...
Ali Hamdan's user avatar
6 votes
1 answer
2k views

Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)

We're on v4.4.10 and keep having to restart the web server due to this issue. I've read various other posts and increased the wp-config.php memory, but still get this error. [23-May-2017 11:39:43 ...
ScottB's user avatar
  • 131
6 votes
1 answer
13k views

How to add a class to the attachment images

When I'm in the Wordpress editor and I add an external image with the 'img' button, my html result wil be like this: <img src="http://example.com/image.jpg" alt="image" /> How can ...
Eric's user avatar
  • 67
6 votes
1 answer
1k views

Inject post (from specific category) between posts in Loop

I would like to add a post (from specific category) between posts in the WordPress Loop (such as 'Sponsors'). Example: P P P S P P S P P S P P How can I achieve this? I am a beginner with coding, so ...
stadisco's user avatar
  • 297
6 votes
3 answers
2k views

How to Control user registrations directly on sub-sites

Does anybody have Idea to enable a wordpress based multisite user to automatically get access to all sub-sites under same Multi site ? If I have A Multi-site installation(Also Buddypress enabled) at ...
Name-AK's user avatar
  • 199
6 votes
1 answer
968 views

How to enable REST API on custom post type without Gutenberg?

I understand that you have to enable the REST API in order to use the Gutenberg block editor, because Gutenberg relies on it; however, I want to use the Classic Editor for a custom post type and still ...
Aristocles's user avatar
6 votes
1 answer
3k views

cURL 28 error after switch from to brew php 7.2 on localhost

I've been running into trouble with all my localhost install of Wordpress reporting cURL error 28 (timeout) since (I believe!)I've switched my PHP version from 7.0 to 7.2 with brew on my local Mac OS ...
kontur's user avatar
  • 152
6 votes
1 answer
5k views

How to run multiple Async HTTP requests in Wordpress?

In my plugin, I want to call 10 or more HTTP requests asynchronously in WordPress so that I need not wait for the response of anyone. Is there any way in Wordpress that supports this and also ...
beginner's user avatar
  • 151