Plugin Directory

Changeset 2473653


Ignore:
Timestamp:
02/12/2021 10:36:45 AM (5 years ago)
Author:
remylmnr
Message:

Version 1.2: Add template format.

Location:
abyssale
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • abyssale/trunk/README.txt

    r2449826 r2473653  
    33Requires at least: 5.5.3
    44Tested up to: 5.5.3
    5 Stable tag: 1.1
     5Stable tag: 1.2
    66Requires PHP: 7.0
    77License: GNU General Public License (GPL) version 3
  • abyssale/trunk/abyssale.php

    r2449826 r2473653  
    33 * Plugin Name: Abyssale
    44 * Description: Create an header image when you create a new blog post.
    5  * Version: 1.1
     5 * Version: 1.2
    66 * Author: Abyssale
    77 * Author URI: https://www.abyssale.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wordpress
     
    6262        $response = $this->abyssaleApi->callAbyssaleApi(
    6363            $settingsOptions["template_id"],
     64            $settingsOptions["format"],
    6465            sanitize_text_field($_POST["title"]),
    6566            get_the_author_meta('display_name', $post->post_author),
     
    206207
    207208        add_settings_field(
     209            'format',
     210            'Template format:',
     211            array($this, 'renderTemplateFormat'),
     212            'abyssale_template_settings',
     213            'section_templates'
     214        );
     215
     216        add_settings_field(
    208217            'title',
    209218            'Wordpress title:',
     
    285294    {
    286295        $output['template_id'] = sanitize_text_field($input['template_id']);
     296        $output['format'] = sanitize_text_field($input['format']);
    287297        $output['title'] = sanitize_text_field($input['title']);
    288298        $output['author_name'] = sanitize_text_field($input['author_name']);
     
    302312        }
    303313
     314        $format = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["format"]);
    304315        $title = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["title"]);
    305316        $authorName = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["author_name"]);
     
    324335                "image" => $image,
    325336                "creation_date" => $creationDate,
     337                "format" => $format,
    326338            )
    327339        );
     
    458470    }
    459471
     472    public function renderTemplateFormat($args)
     473    {
     474        $templateFormats = array();
     475        $optionsApikey = get_option('abyssale_plugin_settings');
     476        $optionsTemplate = get_option('abyssale_plugin_template_settings');
     477        if ($optionsApikey["api_key"] != null && $optionsTemplate["template_id"] != null) {
     478            $response = $this->abyssaleApi->getTemplate($optionsTemplate["template_id"], false);
     479            if ($response["is_error"] == true) {
     480                throw new Exception("An error occurred when retrieving the template.");
     481            }
     482
     483            $templateFormats = $response["template"]["formats"];
     484        }
     485
     486        $options = get_option('abyssale_plugin_template_settings');
     487        printf('<select style="width:300px" id="format" name="%s" value="%s">',  esc_attr('abyssale_plugin_template_settings[format]'), esc_attr($options["format"]));
     488        foreach ($templateFormats as $format) {
     489            if ($format["id"] == $options["format"]) {
     490                echo '<option selected="selected" value="'.esc_attr($format["id"]).'">'.esc_attr($format["id"]).'</option>';
     491            } else {
     492                echo '<option value="'.esc_attr($format["id"]).'">'.esc_attr($format["id"]).'</option>';
     493            }
     494        }
     495        echo '</select>';
     496    }
     497
    460498    public function renderHidden($args)
    461499    {
     
    483521        $response = $this->abyssaleApi->callAbyssaleApi(
    484522            $settingsOptions["template_id"],
     523            $settingsOptions["format"],
    485524            "Title example",
    486525            "Author name",
  • abyssale/trunk/common/abyssale-api.php

    r2435497 r2473653  
    7777    }
    7878
    79     public function callAbyssaleApi($templateId, $title, $authorName, $creationDate, $image, $options)
     79    public function callAbyssaleApi($templateId, $format, $title, $authorName, $creationDate, $image, $options)
    8080    {
    8181        if ($templateId == null) {
     
    8989            "elements" => array()
    9090        );
     91
     92        if ($format != null && $format != "") {
     93            $requestBody["template_format_name"] = $format;
     94        }
     95
    9196        if (isset($options["title"]) && $options["title"] != "" && ($title != "" || $title != null)) {
    9297            $requestBody["elements"][$options["title"]] = array(
     
    124129                'headers'     => array(
    125130                    "x-api-key" => $this->apiKey,
    126                     'Content-Type' => 'application/json'
     131                    'Content-Type' => 'application/json',
     132                    "X-Referer" => "wordpress"
    127133                ),
    128134                'body'        => json_encode($requestBody),
  • abyssale/trunk/partials/admin-settings-display.php

    r2435497 r2473653  
    121121                        jQuery(id).find('option').remove().end().append('<option value="none">None</option>').val('none')
    122122                    }
     123
     124                    jQuery("#format").find('option').remove().end().append('<option value="default">Default</option>').val('default')
    123125                },
    124126                success: function(response) {
    125127                    if("template_id" in response) {
    126                             for (const templateElement of response["elements"]) {
     128                        for (const templateElement of response["elements"]) {
    127129                            jQuery("#title")[0].options.add( new Option(templateElement["name"],templateElement["name"]) )
    128130                            jQuery("#author_name")[0].options.add( new Option(templateElement["name"],templateElement["name"]) )
    129131                            jQuery("#image")[0].options.add( new Option(templateElement["name"],templateElement["name"]) )
    130132                            jQuery("#creation_date")[0].options.add( new Option(templateElement["name"],templateElement["name"]) )
     133                        }
     134
     135                        jQuery("#format").find('option').remove().end();
     136                        for (const format of response["formats"]) {
     137                            jQuery("#format")[0].options.add( new Option(format["id"],format["id"]) )
    131138                        }
    132139                    }
Note: See TracChangeset for help on using the changeset viewer.