Skip to content

Mywp Shortcode Extensions (class)

Extends Shortcode Example

Description

You can extend the your shortcode.

 

Structure

My WP Shortcode the following.

  • MywpShortcode my-wp/shortcode/class.shortcode.php My WP Shortcode API.
  • MywpShortcodeInit my-wp/shortcode/shortcode.init.php Register shortcodes on WordPress already setting data of modules.
  • MywpShortcodeAbstractModule my-wp/shortcode/abstract.shortcode.module.php A class to help register/action the shortcode. You can extend this.

 

How to extend shortcode

Include extend file

Include the your extend class PHP file with add filter.

  • mywp_shortcode_plugins_loaded_include_modules For Plugin Developer Hook
  • mywp_shortcode_after_setup_theme_include_modules For Theme Developer Hook
add_filter( "mywp_shortcode_plugins_loaded_include_modules" , "example_shortcode_include_module" );

function example_shortcode_include_module( $includes ) {

  // Your include path
  $dir = dirname( __FILE__ ) . "/";

  // Your include extend class file name
  $file = $dir . "mywp.shortcode.module.example.php";

  $includes["example_shortcode_include"] = $file;

  return $includes;

}

 

Create the PHP Class extend file.

Create a PHP file, and define the class your name with extend abstract class “MywpShortcodeAbstractModule“.

e.g.) mywp.shortcode.module.example.php

class MywpShortcodeModuleExample extends MywpShortcodeAbstractModule {

}

 

Properties of MywpShortcodeAbstractModule.

MywpShortcodeAbstractModule the following properties.

  • $id require protected static $id is uniqu name and this value is shortcode name.
class MywpShortcodeModuleExample extends MywpShortcodeAbstractModule {

  protected static $id = "mywp_example";

}

e.g.) [mywp_example]

 

Methods of MywpShortcodeAbstractModule.

MywpShortcodeAbstractModule the following methods.

  • mywp_shortcode( $shortcodes ) recommended not override public static This method is setting the shortcode name with shortcode method.
    • $shortcodes (array) Shortcodes in the middle of addition.
  • do_shortcode( $atts , $content = false , $tag ) require public static This method is do action the shortcode name.
    • $atts (array) Shortcodes arguments.
    • $content (string) Shortcodes content.
    • $tag (string) Shortcodes name.
class MywpShortcodeModuleExample extends MywpShortcodeAbstractModule {

  protected static $id = "mywp_example";

  public static function do_shortcode( $atts , $content = false , $tag ) {

    $content = "example";

    return $content;

  }

}

 

Download the example

You can use the example download file and activate the plugin after add plugin of admin plugins panel.

Git Hub: https://github.com/gqevu6bsiz/mywp_shortcode_module_example

  1. Download and Unzip the ZIP file.
  2. Upload the mywp-extend-shortcode-example dir in mywp_shortcode_module_example--master to your WordPress plugins dir.
  3. Activate the My WP Shortcode Extends Example.
  4. Test working the [mywp_example]

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top