Currently workin on my fist plugin ever - your advice wanted

hello dear friends

currently working on my first plugin ever… i need your advice

i want to write an addon that works with the jobify theme from Astoundify.com that puts names and logos from partners to a widget. I want to have an option that allows me to put partner-logos onto my website that runs wp-jobmanager and the jobify-theme. It would be nice if this fits in a widget.

well i have mused some time and finally thought that we can do this like so:

To display partner logos on my website that runs the WP Job Manager and Jobify theme, we can create a custom widget that displays the logos. i have thought about this and i guess that these steps would be necessary:

first we create a custom post type for our partners by adding the following code to your functions.php file:
function create_partner_post_type() {
    register_post_type( 'partner',
        array(
            'labels' => array(
                'name' => __( 'Partners' ),
                'singular_name' => __( 'Partner' )
            ),
            'public' => true,
            'has_archive' => true,
            'menu_icon' => 'dashicons-heart',
        )
    );
}
add_action( 'init', 'create_partner_post_type' );

This code will create a new post type called ‘partner’ with a heart icon in the WordPress admin menu.

**Add custom fields for the partner logo **and website URL by installing and activating the Advanced Custom Fields plugin (link: ).
now we have to create a new field group and add a field for the partner logo and another field for the website URL.

at this step we have to **create a custom widget **that displays our partner logos by adding the following code to your functions.php file:

class Partner_Widget extends WP_Widget {

    function __construct() {
        parent::__construct(
            'partner_widget', 
            __( 'Partner Logos', 'text_domain' ), 
            array( 'description' => __( 'Display partner logos', 'text_domain' ), ) 
        );
    }

    public function widget( $args, $instance ) {
        $partners = get_posts( array(
            'post_type' => 'partner',
            'posts_per_page' => -1,
        ) );

        echo $args['before_widget'];
        if ( ! empty( $instance['title'] ) ) {
            echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
        }

        echo '<div class="partner-logos">';
        foreach ( $partners as $partner ) {
            $logo = get_field( 'partner_logo', $partner->ID );
            $url = get_field( 'partner_url', $partner->ID );
            if ( $logo ) {
                echo '<a href="' . $url . '"><img src="' . $logo['url'] . '" alt="' . $logo['alt'] . '"></a>';
            }
        }
        echo '</div>';

        echo $args['after_widget'];
    }

    public function form( $instance ) {
        $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Partners', 'text_domain' );
        ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
        </p>
        <?php 
    }

    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
        return $instance;
    }
}

function register_partner_widget() {
    register_widget( 'Partner_Widget' );
}
add_action( 'widgets_init', 'register_partner_widget' );

how to use this:

To use this widget, we need to create a custom post type for our partners and add custom fields for the partner logo and website URL using the Advanced Custom Fields plugin. Once we re done that, we can add partners as posts and their logos and website URLs as custom fields.
Then, go to Appearance > Widgets and drag the ‘Partner Logos’ widget to the desired widget area. we can enter a title for the widget and it will display all partner logos with their website URLs in a widget.

It seems to me you have the code part down, what is it that you need help with? Have you tried this code to see if it throws errors? If so can you describe the errors?
Or are you just trying to understand where to put the code? Maybe we may be able to help better if you express a specific question.
Just a suggestion: I think you don’t need ACF for the plugin to work. you can register a CPT and its custom fields directly with the plugin itself very easily (there are free online generators that do exactly this online)
The process is as follows in my head:

  • plugin registers the CPT with the name Partners
  • plugin registers custom meta boxes (custom fields) for URL and Logo for the aforementioned CPT
  • plugin registers widget that contains the function to display Logos in a styled format (you can style it as a row for example) by sourcing them from the CPT
  • The user installs and activates the plugin then goes to the widget setting page and drags the widget where it needs to be and works.
    I think other devs can chime in into this that have more experience than me, but I am for keeping things lean and simple, requiring ACF means you have to add code to the plugin that checks if it is present and throws an error asking the user to install it. It’s more work… :smiley:
2 Likes

I’ve not looked at your code, I’m using my phone.
What I can suggest is:

  • Don’t put code in theme’s function.php but keep all your code i side the plugin.
  • use the featured image for the logo.
  • define custom fields (url) inside your plugin without using another plugin.

Also if you want you can bring the code you need from GitHub - xxsimoxx/affiliates-and-partners. It’s a plugin I started but never finished.

3 Likes

hello dear ElisabettaCarrara, hello dear Simone,

first things first: i am very excited :star_struck: about the discussion - it is very fruitful. :+1: :+1:

first of all many many thanks for the quick reply and all the valuable tipps and ideas you share. I have not tested the code yet. I will testrun this in the next days.

@Simone - many thanks for the hints:

What I can suggest is: Don’t put code in theme’s function.php but keep all your code i side the plugin. use the featured image for the logo.

thats very intersting - to use the featured image for the logo

define custom fields (url) inside your plugin without using another plugin.

Thats a great idea - i think it would be awesome if i would go round the usage of another plugin.

@ElisabettaCarrara, you also mentioned that this would be great if i go round the usage of another plugin. This would be great.

i really like the idea to keep things lean and simple: this is a very convincing idea. I like this idea. Way to go!!!

Simone: you mentioned:

Also if you want you can bring the code you need from GitHub - xxsimoxx/affiliates-and-partners 1. It’s a plugin I started but never finished.

Awesome: Simone i will have a closer look at the code and your github-site. Its awesome.

i am so glad about your tipps and ideas. I will test the code.

as i am pretty new to php-coding: one of the major questions and challenges i have is the qustion if the code runs and the solution works in the jobify-theme (see the link below). This is the question of the day. I run the theme jobify from Astoundify.com - since i need a theme that fits well for the purpose having a good theme for the wp-job-Manager (see link below)

i now will try to get the code of you Simone up and running and will have a closer look if i get a solution.

i come back and will let you know what i found out.

regards fsj-digital :grinning:

btw: see the links - that i think that are important…:

first of all - some very general examples of the type of “sponsorships” on websites…
a. see the site cloudfest dot com scroll down
b. Sponsors | Adobe Summit 2023 | Digital Experience Conference

the theme i run: astoundify dot com /products/jobify/

and - hopefully - we do not need extra plugins like ACF-Plugin: acf is pretty powerful - sure thing but as you both mentioned - we could keep things simple and lean. thats a awesome idea - i try to work this out.

i love to hear from you again - i need your advice - and i love to get simones script working.
:star_struck:

1 Like

dear Simone, dear ElisabethCarrera

well i am so happy that you responded - i a m glad - since i see that there are lean and leightweight solutons out there

so i do not need any heavy products - i can use the lean method.

see what is aimed: see an example:

well do you think that i can do this with the opton that i have on board allready.
can i do this and achieve this with the WordPress Galery with all the options

so - i guess that i can do the job of showing things with the options i have in the theme itself.
see here: https://kb.astoundify.com/article/412-create-individual-testimonials/

hello dear friends,

recap - i run the jobifiy-theme and i eagerly want to use the following features there:

as Simone and ElisabettaCarrara mentioned - the lean and leightweight method is very impressive and i like this.

well that said i guess that we do not need the additional plugins such as
a. wpc - wordpress code - or
b. acf - additional cusstom field

no i am willing to go the smart way. btw the jobify-theme is able to show such things als “companies” that we have helped before.

cf. https://kb.astoundify.com/article/842-home-companies-weve-helped/

This widget requires the “Testimonials by WooThemes” plugin: cf Testimonials by WooThemes – WordPress plugin | WordPress.org
Once you have added your testimonials via “Testimonials > Add New” use this widget to display company logos. Drag the ” Testimonials” widget to the Homepage widget area.

In order for the Testimonials to show the logo only, the settings need to be very specific:

Settings

Title — The title of the widget. This can be anything.
Limit — The number of testimonials to rotate through. This should be 4-6.
Testimonials Per Row: This must be 0
Image Size — This must be 70
Display Author — This must be checked
Display Avatar — This must be checked
Display URL — This must be unchecked
Category — The category you have assigned individuals to

question: why on earth the Testimonials by WooThemes” plugin was not updated for more than 5 years. well this is pretty long time.

but i guess that this method that is described here - this is such a lean and leightweight method and way ö such as Simone and ElisabettaCarrara mentioned

what do you think about the smart way about the method to work with the woocommerce testimonials plugin in order to display the logos and images of the sponsors or partners or clients.

i eagerly love to hear from you

you can use a plugin (woo or another) keep in mind however that if it was not updated in a long time there’s the risk of it getting an update to support wp 5 and above and that it stops working with CP.
Writing your own plugin is VERY EASY considering that you just need to use online generators (like chatGPT or others that already exist) to check your code for mistakes.
And it is far more reliable than an addon that can stop working after some time because it gets updated.
Moreover, if you code this simple plugin you can profit from it by selling it (nobody says an open source software has to be free, you can release something under the GNU license and sell it).
The leaner way is not using other plugins to crowd your site with code you can’t predict when will stop working. It’s writing your own because it is simple enough to do.
I am saying this to encourage you to take the leap, it’s very promising that you have an idea, don’t push it back because you feel overwhelmed because it is worth pursuing.

1 Like

hello dear ElisabettaCarrara :hibiscus:

many thanks for your reply - this is so awesome.:clap::boom::fireworks::star2:

thank you for your reply - this is so great and awesome. you help me - and besides that you help all the ppl who read this same thread.

you can use a plugin (woo or another) keep in mind however that if it was not updated in a long time there’s the risk of it getting an update to support wp 5 and above and that it stops working with CP.
Writing your own plugin is VERY EASY considering that you just need to use online generators (like chatGPT or others that already exist) to check your code for mistakes.

you give me starting points for me to dive into getting solutions to make the next steps… :tada: :gift: :hibiscus::four_leaf_clover:

And it is far more reliable than an addon that can stop working after some time because it gets updated.

ElisabehtCarrera, you describe concepts in multiple ways…; i like the idea of lean-startups see above with the different approaches and you encourage me (and all the novices here) to go ahead with little steps; therefore you provide many good ideas

The leaner way is not using other plugins to crowd your site with code you can’t predict when will stop working. It’s writing your own because it is simple enough to do.

Many thanks - this thread is one of the most intriguing thread of the year for me.

fsj :wink:

1 Like