이 플러그인은 최근 3개의 주요 워드프레스 출시와 시험 되지 않았습니다. 워드프레스의 좀 더 최근 버전으로 이용할 때 더 이상 관리되지 않고 지원되지 않고 호환성 문제가 있을 수 있습니다.

Shortcode Callback

설명

The Shortcode Callback plugin allows you to use a [callback] shortcode to execute arbitrary PHP code wherever the shortcode is used.

Usage

Execute someFunction() and insert whatever it returns with the following shortcode:
[callback function=”someFunction”]

Example shortcode to include a PHP file (the path is relative to WordPress’ ABSPATH), then insert the results of someFunction() where you used the shortcode:
[callback include=”custom/filetoinclude.php” function=”someFunction”]

Shortcode example that includes a PHP file (the path is relative to WordPress’ ABSPATH), then passes a paramter to someFunction() and returns the results where you used the shortcode:
[callback function=”someFunction” include=”custom/filetoinclude.php” param=”something”]

The format to call a class/method with the shortcode is exactly the same as above, except you specify the class::method in the “function” attribute of the shortcode.
[callback function=”someClass::someFunction” include=”custom/filetoinclude.php” param=”something”]

There is an example (with PHP code) over here.

설치

  1. Upload shortcode-callback folder to the /wp-content/plugins/ directory.
  2. Activate the Shortcode Callback plugin through the ‘Plugins’ menu in the WordPress admin area.

FAQ

Do you have an example of where the Shortcode Callback plugin is used?

I built this plugin primarily because I needed a way to inject the “Daily Yield” and “Total Yield” numbers to my solar power chart page.

The shortcode being used:

[callback function=”DigitalPointElectricity::total_output” param=”daily” include=”custom/Electricity.php”]

The `custom/DigitalPointElectricity.php` file being called by the shortcode:

<?php

class DigitalPointElectricity
{
    public static function total_output($timeframe)
    {
        $totals = $GLOBALS['memcache']->get('shawnhogan-pv-total');

        if ($timeframe == 'total')
        {
            return $totals->Items[2]->TotalYield;
        }
        elseif ($timeframe == 'daily')
        {
            return $totals->Items[1]->DailyYield;
        }
    }
}

후기

2016년 12월 29일
This is a really good way of adding some custom code without having to create a new WP plugin. Simply add a php file to your wordpress and display the result using a shortcode. Just remember: Don't use echo or print in your functions or the output will be displayed above your post and not where your shortcode is. To display contents correctly always return them as shown in the examples. To render template files with lots of html: ob_start() require 'my_custom_template.php'; $contents = ob_get_contents(); ob_end_clean(); The resulting output will be stored in the $contents variable thanks to the output buffer. The template file can contain php which will be interpreted like every file that is being included using require().
모든 1 평가 읽기

기여자 & 개발자

“Shortcode Callback”(은)는 오픈 소스 소프트웨어입니다. 다음의 사람들이 이 플러그인에 기여하였습니다.

기여자

자국어로 “Shortcode Callback”(을)를 번역하세요.

개발에 관심이 있으십니까?

코드 탐색하기는, SVN 저장소를 확인하시거나, 개발 기록RSS로 구독하세요.

변경이력

1.0.0

  • Initial release