Advertisement:

Author Topic: Help on some custom fuction  (Read 140 times)

Dimal

  • Full Member
  • ***
  • Posts: 135
Help on some custom fuction
« on: August 19, 2019, 04:27:57 pm »
I see in my Osclass functions.php a custom one at the end. Leftover from the previous webmaster.

Doing some updates now myself, i will move to theme's functions for ease.

That function below, has a small problem: The url of the ad is WITHOUT the permalink, while the permalinks are set and working in all ads. Apparently some error in the function.

It shows the "/index.php?page=item&id=XXXX" and i have no idea why and how to fix that.


The function:


Code: [Select]
<?php
if(!function_exists('usr_published_sent_email')) {
    function 
usr_published_sent_email($item) {
        
// if(osc_is_web_user_logged_in() && is_array($item)) {
    
if(osc_is_web_user_logged_in() && is_array($item)) {

            
$user User::newInstance()->findByPrimaryKey(osc_logged_user_id());
            
$ad osc_item_url_ns($item['pk_i_id']);

            
$title 'Thanks for posting!';

            
$body =  'Hi there,<br>';
            
$body .= '<br>';
            
$body .= 'To see if your published ad: (' $item["s_title"] . ') looks all good check it out here: <br><br>';
            
$body .= $ad "<br>";
            
$body .= '<br>';
            
$body .= 'In case the ad looks bad (visually), it will be removed by Admin! :)<br>';
            
$body .= '<br>';
            
$body .= 'Also you may want to keep this email for your archive <br>';
            
$body .= 'Kind regards,<br>';
            
$body .= 'Admin & Your Ad(s) Guardian';

            
$emailParams =  array('subject'  => $title
                                
,'to'       => $user['s_email']
                                ,
'to_name'  => $user['s_name']
                                ,
'body'     => $body
                                
,'alt_body' => $body);

            
osc_sendMail($emailParams);
        }
    }
    
osc_add_hook('posted_item''usr_published_sent_email');
}
?>



I would appreciate any help.

Thanks


calinbehtuk

  • Sr. Member
  • ****
  • Posts: 486
Re: Help on some custom fuction
« Reply #1 on: August 19, 2019, 05:39:28 pm »
Code: [Select]
<?php
if(!function_exists('usr_published_sent_email')) {
    function 
usr_published_sent_email($item) {
        
// if(osc_is_web_user_logged_in() && is_array($item)) {
    
if(osc_is_web_user_logged_in() && is_array($item)) {

            
$user User::newInstance()->findByPrimaryKey(osc_logged_user_id());
            
View::newInstance()->_exportVariableToView('item'$item);
            
$ad osc_item_url();

            
$title 'Thanks for posting!';

            
$body =  'Hi there,<br>';
            
$body .= '<br>';
            
$body .= 'To see if your published ad: (' $item["s_title"] . ') looks all good check it out here: <br><br>';
            
$body .= $ad "<br>";
            
$body .= '<br>';
            
$body .= 'In case the ad looks bad (visually), it will be removed by Admin! :)<br>';
            
$body .= '<br>';
            
$body .= 'Also you may want to keep this email for your archive <br>';
            
$body .= 'Kind regards,<br>';
            
$body .= 'Admin & Your Ad(s) Guardian';

            
$emailParams =  array('subject'  => $title
                                
,'to'       => $user['s_email']
                                ,
'to_name'  => $user['s_name']
                                ,
'body'     => $body
                                
,'alt_body' => $body);

            
osc_sendMail($emailParams);
        }
    }
    
osc_add_hook('posted_item''usr_published_sent_email');
}
?>


Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help on some custom fuction
« Reply #2 on: August 19, 2019, 06:43:35 pm »
Thanks a LOT. Works ok now.

Dev101 suggested i could use a plugin for that, instead of functions.php. Is it enough to put that function in index.php and create a plugin, with the "header" i see in other plugins (commented descriptions etc etc) ?


calinbehtuk

  • Sr. Member
  • ****
  • Posts: 486
Re: Help on some custom fuction
« Reply #3 on: August 19, 2019, 07:04:06 pm »
My suggestion for you is to create a plugin where you can add all your changes, functions like this or other type of change that can run only with hooks. In this way you can make updates on your theme and to osclass script(if they will be other updates for osclass).

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help on some custom fuction
« Reply #4 on: August 19, 2019, 07:51:09 pm »
My suggestion for you is to create a plugin where you can add all your changes, functions like this or other type of change that can run only with hooks. In this way you can make updates on your theme and to osclass script(if they will be other updates for osclass).

I didn't know i could do that. Yes, i have 2-3 functions ONLY with hooks. I will try your suggestion.

Again, thanks for your replies.


cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1196
Re: Help on some custom fuction
« Reply #5 on: August 19, 2019, 08:45:29 pm »
you can also use create a child theme https://doc.osclass.org/How_to_create_a_child_theme

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help on some custom fuction
« Reply #6 on: August 19, 2019, 09:28:39 pm »
you can also use create a child theme https://doc.osclass.org/How_to_create_a_child_theme

I will not do that for the functions, the plugin is easier.

BUT thanks for let me know about that, i WILL use that technic for css and other small mods of the theme, that i'm going to update (Osclass Wizards from 204 to 206).

Because right now o struggle with CodeCompare to see what changes must i do.

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help on some custom fuction
« Reply #7 on: August 20, 2019, 02:45:48 am »
you can also use create a child theme https://doc.osclass.org/How_to_create_a_child_theme

Alas .... trying to make a child theme for Osclasswizards, following the above link, it doesn't seem to work at all. Also there are no instructions about it. For example you must activate as main theme the theme or the child ?

Still, tried both, i was not able to change the footer or the header. I havent' tried anything else.