May 4, 2011

Calling a function from the PHP code of a feed | CyberSEO Pro | Support Forum

Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_TopicIcon
Calling a function from the PHP code of a feed
Topic Rating: 0 Topic Rating: 0 Topic Rating: 0 Topic Rating: 0 Topic Rating: 0 Topic Rating: 0 (0 votes) 
March 13, 2023
12:39 pm
Avatar
MediFormatica
Member
Members
Forum Posts: 49
Member Since:
December 17, 2022
sp_UserOfflineSmall Offline

Hello,

I have written some code to extract the featured image from non-compliant feeds and I want to use it in many feeds. I have been copy pasting it but every time I need to make a change I have to go through all the feeds.

Is there a way to create a function that can be called from with the CSEO PHP field in the feed setup?

I created a function in a code snippet that is set to run everywhere but when I try to call it from CSEO i get an error. The function should return an array of values.

--Call to function

$mfi_cseo = cseo_featuredthumb('fulltext', $mfi_post_link, trim($mfi_post_content), '');

--Error

[13-03-23 11:03:50] Executing user-defined PHP code
[13-03-23 11:03:52] Error: Undefined constant "cseo_featuredthumb"

March 13, 2023
1:26 pm
Avatar
CyberSEO
Admin
Forum Posts: 3947
Member Since:
July 2, 2009
sp_UserOfflineSmall Offline

I'm not sure I've got it. You say you defined a function in PHP code snippet. The CyberSEO Pro PHP snippet is a function itself, so you can't define any functions there. You can just call them in your snippets if they are defined elsewhere.

Usually the theme's functions.php file is being used as a place that contains all user-defined functions: Login to see this link

March 13, 2023
2:16 pm
Avatar
MediFormatica
Member
Members
Forum Posts: 49
Member Since:
December 17, 2022
sp_UserOfflineSmall Offline

Sorry, I should've explained better.

I'm using the Code Snippets plugin (Login to see this link) which allows me to add code snippets that run across the website with directly editing the functions.php file. I'm using for adding so custom code for other functions and automating stuff as well.

So, hypothetically, we can say that the function is indeed inside the functions.php file. Would I be able to call it from the feed's PHP field?

March 13, 2023
2:33 pm
Avatar
CyberSEO
Admin
Forum Posts: 3947
Member Since:
July 2, 2009
sp_UserOfflineSmall Offline

Depends which plugin runs first by WordPress. If CyberSEO Pro is being launched before that plugin, then the functions, declared there won't be loaded. Otherwise they will be available like any WordPress API functions or functions defined in your theme or other plugins.

That's why functions.php is a 100% working solution and is suggested for custom-defined functions in all WordPress manuals.

March 13, 2023
11:26 pm
Avatar
MediFormatica
Member
Members
Forum Posts: 49
Member Since:
December 17, 2022
sp_UserOfflineSmall Offline

Thank you.

I needed to add a filter hook and an action.

Now it works well.

Forum Timezone: Europe/Amsterdam

Most Users Ever Online: 541

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

ninja321: 84

s.baryshev.aoasp: 68

Freedom: 61

Pandermos: 54

MediFormatica: 49

B8europe: 48

Member Stats:

Guest Posters: 337

Members: 2852

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 5

Topics: 1640

Posts: 8352

Newest Members:

torontomark48, info.ckmedianetwork, contact.mybeautystar, samuelbodde, john.prush, creightonnick0

Administrators: CyberSEO: 3947