创建一个从另一个类继承的自定义类PHP

时间:2019-10-23 22:41:44

标签: php wordpress

在我的Wordpress网站上,当我当前正在调用简码时,我的班级返回cta cta-white ct-arrow。

我希望能够从cta cta-white ct-arrow创建一个自定义类名,将其更改为cta cta-white ct-arrow1之类的名称。

有人可以帮我吗?

谢谢

请忽略 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。

<?php

global $SITE;
$SITE = new SiteObject();
$SITE->init();

function SITE() {
    global $SITE;
    return $SITE;
}

class SiteObject {

    public $meta_title = '';
    public $meta_desc = '';
    public $meta_img = '';

    function init() {
        add_action('init', function() {
            register_nav_menu('main-menu', __( 'Main Menu' ));
            add_image_size('1280', 1280);
            add_image_size('1920', 1920);
            add_shortcode('cta', [$this, 'ctaShortcode']);
            add_shortcode('contact-social', [$this, 'contactSocialShortcode']);
            add_shortcode('doc-upload', [$this, 'docUploadShortcode']);
            get_role('editor')->add_cap('edit_theme_options');
        });

        if (!is_admin()) {
            add_action('wp', [$this, 'setupMeta']);
        }

        add_filter('flamingo_map_meta_cap', function($meta_caps) {
            $meta_caps = array_merge($meta_caps, [
                'flamingo_edit_contact' => 'edit_pages',
                'flamingo_edit_contacts' => 'edit_pages',
                'flamingo_delete_contact' => 'edit_pages',
                'flamingo_delete_contacts' => 'edit_pages',
                'flamingo_edit_inbound_message' => 'edit_pages',
                'flamingo_edit_inbound_messages' => 'edit_pages',
                'flamingo_delete_inbound_message' => 'edit_pages',
                'flamingo_delete_inbound_messages' => 'edit_pages',
                'flamingo_spam_inbound_message' => 'edit_pages',
                'flamingo_unspam_inbound_message' => 'edit_pages'
            ]);

            return $meta_caps;
        });

    }

    function setupMeta() {
        $post = get_post();

        if ($post) {
            $this->meta_title = trim(get_the_title($post->ID));
            $this->meta_desc = trim(get_the_excerpt($post));
            $this->meta_img = get_the_post_thumbnail_url($post->ID, 'large');
        }

        $home_post = get_post(url_to_postid('home'));

        if ($home_post) {
            if (empty($this->meta_title)) {
                $this->meta_title = trim(get_the_title($home_post->ID));
            }

            if (empty($this->meta_desc)) {
                $this->meta_desc = trim(get_the_excerpt($home_post));
            }

            if (empty($this->meta_img)) {
                $this->meta_img = get_the_post_thumbnail_url($home_post->ID, 'large');
            }
        }
    }

    function getMeta($type) {
        return esc_attr($this->$type);
    }

    function resource($path) {
        return get_bloginfo('template_url')."/_resources/{$path}";
    }

    function font($name) {
        return $this->resource("fonts/{$name}/{$name}.css");
    }

    function svg($name) {
        return file_get_contents(__DIR__."/_resources/{$path}");
    }


    function ctaShortcode($atts, $content = null) {

        if ($atts['colour'] == 'orange') {
            $colour = 'cta-orange';
        } else if ($atts['colour'] == 'white') {
            $colour = 'cta-white';
        }

        if ($atts['style'] == 'outlined') {
            $style = 'cta-empty';
        } else if ($atts['style'] == 'filled') {
            $style = 'cta-filled';
        } else if ($atts['style'] == 'arrow') {
            $style = 'cta-arrow';
        }

        if ($atts['block'] == 'true') {
            $block = 'cta-block';
        } else {
            $block = '';
        }
        /*
        $test = '';
        if ($atts['newwindow'] == 'true') {
            $test = '_blank';
        } else {
            $test = '_self';
        }
        */
        return "<a href='{$atts['link']}' ><div class='cta {$colour} {$style} {$block}'>{$content}</div></a>";

    }

    function contactSocialShortcode($atts, $content = null) {
        $img = SITE()->resource("artwork/contact-{$atts['icon']}.svg");
        return "<a href='{$atts['link']}'><img class='contact-social' src='{$img}'></a>";
    }

    function docUploadShortcode($atts, $content = null) {
        return "<form action='http://119.9.12.161/api/v1.0/attachments' method='post'>
            <div class='form-cell'>
                <input type='file' name='file'>
            </div>
            <div class='form-cell'>
                <input type='submit' value='Send' class='cta cta-empty cta-orange'>
            </div>
        </form>";
    }

    function registrationURL() {
        return '/registration';
    }

}

include 'button.php';

?>

0 个答案:

没有答案