Skip to content

Forum in maintenance, we will back soon 🙂

Basic PHP Snippet t...
 
Notifications
Clear all

Basic PHP Snippet to Generate Titles

15 Posts
3 Users
12 Reactions
294 Views
(@thomas-gaye)
Posts: 1
New Member Customer Registered
Topic starter
 

 

Screenshot 2024 02 04 230906

Hi Hasan, 

I'm a new student to your platform and I'm getting error message for this code, ( see below) can you assist me or point me to a solution?

 

// This is the start of a function named 'return_fixed_titles'. 
// Functions are like recipes: they contain instructions that tell the computer what to do.
function return_fixed_titles() {
    // Here we're creating a list (or 'array') of titles. 
    // Each title is a text string, and they are all enclosed in quotation marks and separated by commas.
    $titles = [
        "Discovering the Secrets of the Ocean Depths",
        "The Art of Sourdough Bread Making",
        "Exploring the Hidden World of Insects",
    ];

    // This line sends the list of titles back to whoever or whatever asked for it.
    // 'wp_send_json_success' is a special WordPress function that sends data in a format called JSON,
    // which is commonly used in web programming to exchange data.
    wp_send_json_success($titles);

    // 'wp_die()' is another WordPress function.
    // It's used here to tell WordPress that our function is done and it can stop running.
    // This is necessary for all functions that respond to AJAX requests in WordPress.
    wp_die();
}

// These next two lines are about connecting our function to WordPress.
// They tell WordPress, "When you get an AJAX request named 'return_fixed_titles', run our function."

// 'add_action' is a WordPress function that lets us hook our custom function into WordPress.
// 'wp_ajax_return_fixed_titles' tells WordPress to use our function when logged-in users make the request.
add_action('wp_ajax_return_fixed_titles', 'return_fixed_titles');

// 'wp_ajax_nopriv_return_fixed_titles' does the same thing for users who are not logged in.
add_action('wp_ajax_nopriv_return_fixed_titles', 'return_fixed_titles');
 
Posted : 02/05/2024 4:10 am
Appanna M and brahim reacted
(@avrahim)
Posts: 6
Member
 

I get this error too and I couldn't get rid of it first I thought it's my wordpress installation I remove it and install it again but nothing changes, Help please

 
Posted : 02/05/2024 10:23 am
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

Hi friends, I am testing this, and I will get back to you 

 
Posted : 02/05/2024 12:21 pm
brahim reacted
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

I tested it from my side on deepdiveopenai, this is a security feature in the browser causing this.

please add the following lines to the top of the function and try again:

// Add CORS headers
        header('Access-Control-Allow-Origin: *'); // Allows all origins
        header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); // Specifies the allowed methods
        header('Access-Control-Allow-Headers: Content-Type, Authorization'); // Specifies the allowed headers
 
Posted : 02/05/2024 2:08 pm
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

See it is working:

Screenshot 2024 02 05 160910
 
Posted : 02/05/2024 2:09 pm
brahim reacted
(@avrahim)
Posts: 6
Member
 

It works thanks a lot Mr: Hasan @admin

 
Posted : 02/05/2024 2:20 pm
(@avrahim)
Posts: 6
Member
 

Hello again Mr: Hassan 

Well, the solution you give worked perfectly but in my case I want to use assistant API instead of prompt in the php script but I found some problems like how I make the assistant replay in the same topic I used a powerful prompt in that assistant Please some help here @admin 

 
Posted : 02/05/2024 3:18 pm
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

@avrahim, do you want to integrate assistant APIs in PHP ? or do you have a Python backend? please explain your scenario in more detail

 
Posted : 02/05/2024 3:23 pm
(@avrahim)
Posts: 6
Member
 

I'd like to use python to integrate assistant api in my wordpress tools but that assistant API ask user for more information so it's not simple as your tools I'll demonstrate in this example from playground chat, this example is about a tiktok hook generator I ask him to give me hooks about : compare between 2 vacuum cleaners on amazon 

this is the assistant API response:

 

Hooks Generator

It seems like you're interested in comparing two vacuum cleaners on Amazon. While my primary focus is on creating TikTok hooks, I can guide you on how to frame your comparison in a catchy and engaging way for a potential TikTok video. Let's go through the framework to craft a compelling hook for your comparison video.

First, let's start with the definition:

  1. Video Content: Could you provide a brief explanation of the key features, benefits, and unique selling points of the two vacuum cleaners you want to compare? What makes them stand out from each other?

  2. Target Audience: Who is your target audience for this comparison? What demographics and interests do they have? Understanding your audience will help tailor the hook to resonate with them.

  3. Emotional Impact: What emotional response do you want to evoke in your audience with this comparison? Are you aiming for informative, exciting, practical, or any other emotional impact?

  4. Crafting the Hook: Based on the information you provided, we can craft a hook that captures the essence of the comparison and resonates with your audience.

Once we have the details, we can move on to analyzing the latest trends and psychological triggers to trendify your hook for maximum engagement. Let's start with defining the key aspects of the comparison first.

 

now the user have to entre what the assistant ask and then it gives him more detailed and catchy hooks.

this what I'm trying to build but found some difficult in linking assistant API with the user interface and the python backend

 
Posted : 02/05/2024 6:25 pm
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

@avrahim, why don't you create the tool with 3-4 inputs, and the user submits directly? why you are using the assistant API here?

 
Posted : 02/06/2024 12:26 pm
brahim reacted
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

I am building a hooks generator, take a look:

Screenshot 2024 02 06 142724
 
Posted : 02/06/2024 12:27 pm
brahim reacted
(@avrahim)
Posts: 6
Member
 

yes I want something like that is this tool on this website? can you send me the source code of this tool please ! 

 
Posted : 02/06/2024 1:05 pm
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

@avrahim I didnt finish it yet. When I am done with it, I will be sharing a tutorial with the code on how I built it, and it will be free for you as a power member 🙂

 
Posted : 02/07/2024 7:41 am
brahim reacted
(@avrahim)
Posts: 6
Member
 

@admin Thanks a lot 

 
Posted : 02/07/2024 10:12 am
Hasan Aboul Hasan
(@admin)
Posts: 1257
Member Admin
 

@avrahim Published a full course about it, please check

 
Posted : 03/16/2024 3:04 pm
Share: